2

I need to list the active audio sessions. I am using the next code:

MediaSessionManager mediaSessionManager = (MediaSessionManager) 
    getSystemService(Context.MEDIA_SESSION_SERVICE);

ComponentName componentName = new ComponentName(this, 
    NotificationListenerExampleService.class);

List<MediaController> controllers = 
    mediaSessionManager.getActiveSessions(componentName);

Error: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.bassbooster/com.example.bassbooster.MainActivity}: java.lang.SecurityException: Missing permission to control media.

The permission "android.Manifest.permission.MEDIA_CONTENT_CONTROL", is only for system apps.

How can i list the active audio sessions?

Thanks for reading.

Kevin La Delfa
  • 69
  • 1
  • 10

1 Answers1

-2

If you not ask that permission at runtime, so add permission at runtime. Runtime permission require only for marshmellow or above. You must have to ask runtime permissions in or above marshmellow

Swapneil
  • 1
  • 1
  • When answering a question that deals with coding, it is better to slip in a few relevant codes. – Taseer Jul 06 '19 at 08:04