I am creating a music player application. I want to show the media controller on notification bar while my application is running in background. It looks like Google player.
How to do this?
I am creating a music player application. I want to show the media controller on notification bar while my application is running in background. It looks like Google player.
How to do this?
Return/send data from notification to your original Activity; the changes needed for the Example above:
How to use the Notification Button to resume the same Stack and Activity that created the Notification:
1) Make sure the Activity is not Destroyed (optional), change the Back button to put the task in the back and not destroy it:
2) In the Menifest add this to the Activity:
3) Add those flags for your Intent Instance: (volume is the Intent instance)
and as well you can add the following (optional):
4) In the PendingIntent instance don't use any flags:
5) And catch the intent in your Activity with onNewIntent(Intent intent) call back:
Here is the example above done correctly to the new API
In your main, when you want to start a notification instantiate the class:
And when you want to cancel notification: (as it is an onGoing notification)
Then create the class for the notification caller:
Then add the return class that accept the pending intent:
Then you need to make a XML file for the button. This is a simple one:
Last and not least, the Manifest file:
You need to create a RemoteView and show it as a notification.
Please refer to the follow document
Status Notifications (Creating a Custom Notification Layout)
For getting media player controller in your app simply follow this:
Call this method in your MainActivity
Create a new MynotificationClass
Create a HelperActivity class
XML layout for Notificationlayout.xml