Missing permission to control media error on Android 5/L

元气小坏坏 提交于 2020-01-15 07:00:21

问题


Missing permission to control media error on Android 5/L

Got the below error on this line while trying to setup a RemoteController. I couldn't find any info on this error so wanted to post the error and the simple solution.

Code that triggered it:

if(!((AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE)).registerRemoteController(mRemoteController)) {...}

Error:

E/AndroidRuntime(21073): FATAL EXCEPTION: main
E/AndroidRuntime(21073): Process: com.example.widgetdemo, PID: 21073
E/AndroidRuntime(21073): java.lang.SecurityException: Missing permission to control media.
E/AndroidRuntime(21073):    at android.os.Parcel.readException(Parcel.java:1540)
E/AndroidRuntime(21073):    at android.os.Parcel.readException(Parcel.java:1493)
E/AndroidRuntime(21073):    at android.media.session.ISessionManager$Stub$Proxy.addSessionsListener(ISessionManager.java:274)
E/AndroidRuntime(21073):    at android.media.session.MediaSessionManager.addOnActiveSessionsChangedListener(MediaSessionManager.java:208)
E/AndroidRuntime(21073):    at android.media.RemoteController.startListeningToSessions(RemoteController.java:796)
E/AndroidRuntime(21073):    at android.media.AudioManager.registerRemoteController(AudioManager.java:2530)
E/AndroidRuntime(21073):    at com.example.widgetdemo.RemoteControlService.setRemoteControllerEnabled(RemoteControlService.java:68)
E/AndroidRuntime(21073):    at com.example.widgetdemo.MainActivity$3.onServiceConnected(MainActivity.java:216)
E/AndroidRuntime(21073):    at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1203)
E/AndroidRuntime(21073):    at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1220)

回答1:


User needs to explicitly give your app Notification access permission, by going to Settings -> Sound & Notification -> Notification access -> Select checkbox next to your app



来源:https://stackoverflow.com/questions/27993446/missing-permission-to-control-media-error-on-android-5-l

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