[Android] Prevent SecurityException on Android 7+

Geoffrey Métais git at videolan.org
Mon Jul 10 15:57:30 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Mon Jul 10 15:11:51 2017 +0200| [ef7eec280f8e1297603514dc69d4c9f959572ef2] | committer: Geoffrey Métais

Prevent SecurityException on  Android 7+

> https://code.videolan.org/videolan/vlc-android/commit/ef7eec280f8e1297603514dc69d4c9f959572ef2
---

 vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
index c9ca4289c..78e695582 100644
--- a/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/video/VideoPlayerActivity.java
@@ -2242,7 +2242,8 @@ public class VideoPlayerActivity extends AppCompatActivity implements IVLCVout.C
     }
 
     private void setAudioVolume(int vol) {
-        mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, vol, 0);
+        if (vol <= 0 && AndroidUtil.isNougatOrLater)
+            return; //Android N+ throws "SecurityException: Not allowed to change Do Not Disturb state"
 
         /* Since android 4.3, the safe volume warning dialog is displayed only with the FLAG_SHOW_UI flag.
          * We don't want to always show the default UI volume, so show it only when volume is not set. */



More information about the Android mailing list