How to use MediaSessionCompat?
How do I use a MediaSessionCompat? Can someone give a simple working example?
I’ve found some, but they use:
MediaSessionCompat _mediaSession = new MediaSessionCompat(context, "tag");
This gives me error:
The constructor MediaSessionCompat(Context, String) is undefined and wants me to use
MediaSessionCompat(Context, String, ComponentName, PendingIntent)
3 Solutions collect form web for “How to use MediaSessionCompat?”
SampleMediaRouterActivity.java in Support7Demos seems to be a good place to start.
I found a working example here, which I tested both on kitkat and marshmallow.
But do take note, sometimes, sometimes lock screen control don’t appear because of android settings(i.e Settings > Sounds & Notifications > Notification > While Locked > Hide Sensitive Content) See below:
MediaSessionCompat is in
android.support.v4 and that is the Constructor it uses.. it is a backward compatibility for
MediaSession introduced in api 21, and this is its Contrustor;. However if you want to use the Constructor you are referring to you need to compile your project with api 21+;