[Android] Permission dialog and check for drawing overlays
Geoffrey Métais
git at videolan.org
Fri Apr 1 12:04:03 CEST 2016
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Mar 31 13:07:46 2016 +0200| [e73d1ac34e93fbb118cb49ebc5991f69935d6233] | committer: Geoffrey Métais
Permission dialog and check for drawing overlays
> https://code.videolan.org/videolan/vlc-android/commit/e73d1ac34e93fbb118cb49ebc5991f69935d6233
---
vlc-android/res/values/strings.xml | 2 ++
.../src/org/videolan/vlc/util/Permissions.java | 21 ++++++++++++++++++++-
2 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/vlc-android/res/values/strings.xml b/vlc-android/res/values/strings.xml
index 403cce3..c89a73a 100644
--- a/vlc-android/res/values/strings.xml
+++ b/vlc-android/res/values/strings.xml
@@ -404,6 +404,8 @@
<string name="allow_settings_access_ringtone_description">VLC needs you to grant this permission to set up this song as your ringtone.</string>
<string name="allow_settings_access_brightness_title">Allow VLC to change brightness mode</string>
<string name="allow_settings_access_brightness_description">VLC needs you to grant this permission to change your brightness mode.</string>
+ <string name="allow_draw_overlays_title">Allow VLC player popup over other apps</string>
+ <string name="allow_sdraw_overlays_description">VLC needs you to grant this permission display your video in a popup over other applications.</string>
<string name="permission_ask_again">Grant permission</string>
<string name="exit_app">Close VLC</string>
<string name="hardware_acceleration_error">hardware acceleration error, switching to software decoding</string>
diff --git a/vlc-android/src/org/videolan/vlc/util/Permissions.java b/vlc-android/src/org/videolan/vlc/util/Permissions.java
index ae0cbe3..edae7e7 100644
--- a/vlc-android/src/org/videolan/vlc/util/Permissions.java
+++ b/vlc-android/src/org/videolan/vlc/util/Permissions.java
@@ -53,12 +53,18 @@ public class Permissions {
public static final int PERMISSION_SYSTEM_RINGTONE = 42;
public static final int PERMISSION_SYSTEM_BRIGHTNESS = 43;
+ public static final int PERMISSION_SYSTEM_DRAW_OVRLAYS = 44;
/*
* Marshmallow permission system management
*/
@TargetApi(Build.VERSION_CODES.M)
+ public static boolean canDrawOverlays(Context context) {
+ return !AndroidUtil.isMarshMallowOrLater() || Settings.canDrawOverlays(context);
+ }
+
+ @TargetApi(Build.VERSION_CODES.M)
public static boolean canWriteSettings(Context context) {
return !AndroidUtil.isMarshMallowOrLater() || Settings.System.canWrite(context);
}
@@ -82,6 +88,12 @@ public class Permissions {
}
}
+ public static void checkDrawOverlaysPermission(Activity activity) {
+ if (AndroidUtil.isMarshMallowOrLater() && !canDrawOverlays(activity)) {
+ showSettingsPermissionDialog(activity, PERMISSION_SYSTEM_DRAW_OVRLAYS);
+ }
+ }
+
public static void checkWriteSettingsPermission(Activity activity, int mode) {
if (AndroidUtil.isMarshMallowOrLater() && !canWriteSettings(activity)) {
showSettingsPermissionDialog(activity, mode);
@@ -183,6 +195,7 @@ public class Permissions {
private static Dialog createSettingsDialogCompat(final Activity activity, int mode) {
int titleId = 0, textId = 0;
+ String action = Settings.ACTION_MANAGE_WRITE_SETTINGS;
switch (mode) {
case PERMISSION_SYSTEM_RINGTONE:
titleId = R.string.allow_settings_access_ringtone_title;
@@ -192,7 +205,13 @@ public class Permissions {
titleId = R.string.allow_settings_access_brightness_title;
textId = R.string.allow_settings_access_brightness_description;
break;
+ case PERMISSION_SYSTEM_DRAW_OVRLAYS:
+ titleId = R.string.allow_draw_overlays_title;
+ textId = R.string.allow_sdraw_overlays_description;
+ action = Settings.ACTION_MANAGE_OVERLAY_PERMISSION;
+ break;
}
+ final String finalAction = action;
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(activity)
.setTitle(activity.getString(titleId))
.setMessage(activity.getString(textId))
@@ -201,7 +220,7 @@ public class Permissions {
@Override
public void onClick(DialogInterface dialog, int whichButton) {
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(activity);
- Intent i = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS);
+ Intent i = new Intent(finalAction);
i.setData(Uri.parse("package:" + activity.getPackageName()));
try {
activity.startActivity(i);
More information about the Android
mailing list