问题
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