i am trying to use MediaSessionManager in API21, to control the music play on the device. For the usage, it says need to held the android.Manifest.permission.MEDIA_CONTENT_CONTROL:
public void addOnActiveSessionsChangedListener (MediaSessionManager.OnActiveSessionsChangedListener sessionListener, ComponentName notificationListener, Handler handler)
Added in API level 21
Add a listener to be notified when the list of active sessions changes.***This requires the android.Manifest.permission.MEDIA_CONTENT_CONTROL permission be held by the calling app.*** You may also retrieve this list if your app is an enabled notification listener using the NotificationListenerService APIs, in which case you must pass the ComponentName of your enabled listener. Updates will be posted to the handler specified or to the caller's thread if the handler is null.
I don't have a notification service. But by adding the <uses-permission android:name="android.permission.MEDIA_CONTENT_CONTROL"/>
in AndroidManifest.xml, and check the permission in code with PackageManager.PERMISSION_GRANTED == context.checkCallingOrSelfPermission(android.Manifest.permission.MEDIA_CONTENT_CONTROL)
it returns false always, and the app will crash with security exception.
How to get the permission correctly? i check the permission introduction,
public static final String MEDIA_CONTENT_CONTROL
Added in API level 19
Allows an application to know what content is playing and control its playback.
***Not for use by third-party applications due to privacy of media consumption***
Constant Value: "android.permission.MEDIA_CONTENT_CONTROL"
Is the "Not for use by third-party applications" makes the permission different, and common application can't get it?
Unfortunately, this permission is only restricted to either system apps(apps which are part of system image) or the apps which belongs to the vendor the device (ie. app signature must be same as platform's). So for third party apps this is not allowed.
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