我正在尝试使用 API21 中的 MediaSessionManager 来控制设备上的音乐播放。
对于使用,它说需要持有 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.
我没有通知服务。但是通过添加<uses-permission android:name="android.permission.MEDIA_CONTENT_CONTROL"/>
在 AndroidManifest.xml 中,并检查代码中的权限PackageManager.PERMISSION_GRANTED == context.checkCallingOrSelfPermission(android.Manifest.permission.MEDIA_CONTENT_CONTROL)
它总是返回 false,并且应用程序将因安全异常而崩溃。
如何正确获取权限?我查看了权限介绍,
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"
难道“不供第三方应用使用”使得权限不同,普通应用无法获取?
不幸的是,此权限仅限于系统应用程序(属于系统映像的应用程序)或属于设备供应商的应用程序(即应用程序签名必须与平台的签名相同)。因此对于第三方应用程序来说这是不允许的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)