I'm looking to create a media style notification for a music app i'm creating but i want to keep older Android users (ICS up) in mind also. I would like it to contain play/pause controls.
What's the best way that i can do this? Should i create a custom notification for anyone below Android Lollipop and use a media style notification for Android Lollipop? Or should i just go ahead and make a custom notification for both? Using NotificationCompat doesn't seem possible after a bit of experimentation.
Any examples would be greatly appreciated.
While either will work, I'd suggest using the first approach. It doesn't look like there is an intention of adding MediaStyle support to NotificationCompat any time soon, based on the note listed here, which states:
Note: The template and the addAction() method are not included in the support library, so these features run in Android 5.0 and higher only.
In my case, I have a boolean that identifies the API level:
boolean mIsLollipopOrAbove = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
When it comes time to make the notification, I just check that and either use a custom notification or build the MediaStyle notification based on the version of Android the user is running. To support lock screen controls, I'm using the latest version of the support libraries and interacting with MediaSessionCompat, which will still use the RemoteControlClient under the hood when required on pre-Lollipop devices. You can pass the token for your MediaSessionCompat to the MediaStyle notification, which facilitates updating the lock screen image based on the media that is playing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With