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

早过忘川 提交于 2019-12-07 11:49:22

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/27633509/how-to-get-android-permission-of-android-manifest-permission-media-content-contr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!