Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get android permission of android.Manifest.permission.MEDIA_CONTENT_CONTROL

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?

like image 853
Sarah Ma Avatar asked Sep 29 '22 03:09

Sarah Ma


1 Answers

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.

like image 144
Neeraj Nama Avatar answered Oct 04 '22 02:10

Neeraj Nama