mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-26 02:25:50 +01:00
Catch SecurityException when Notfication access was not granted when getting media session
Fixes #1387
This commit is contained in:
parent
629dcfdec2
commit
b4bbf6186c
@ -106,14 +106,17 @@ public class GBMusicControlReceiver extends BroadcastReceiver {
|
|||||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
|
||||||
MediaSessionManager mediaSessionManager =
|
MediaSessionManager mediaSessionManager =
|
||||||
(MediaSessionManager) context.getSystemService(Context.MEDIA_SESSION_SERVICE);
|
(MediaSessionManager) context.getSystemService(Context.MEDIA_SESSION_SERVICE);
|
||||||
|
|
||||||
List<MediaController> controllers = mediaSessionManager.getActiveSessions(
|
|
||||||
new ComponentName(context, NotificationListener.class));
|
|
||||||
try {
|
try {
|
||||||
MediaController controller = controllers.get(0);
|
List<MediaController> controllers = mediaSessionManager.getActiveSessions(
|
||||||
audioPlayer = controller.getPackageName();
|
new ComponentName(context, NotificationListener.class));
|
||||||
} catch (IndexOutOfBoundsException e) {
|
try {
|
||||||
LOG.error("No media controller available", e);
|
MediaController controller = controllers.get(0);
|
||||||
|
audioPlayer = controller.getPackageName();
|
||||||
|
} catch (IndexOutOfBoundsException e) {
|
||||||
|
LOG.error("No media controller available", e);
|
||||||
|
}
|
||||||
|
} catch (SecurityException e) {
|
||||||
|
LOG.warn("No permission to get media sessions - did not grant notification access?", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return audioPlayer;
|
return audioPlayer;
|
||||||
|
Loading…
Reference in New Issue
Block a user