mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2025-09-05 12:27:55 +00:00
Permission: display explanatory dialog for Android > R
On Android > R, ACTION_MANAGE_OVERLAY_PERMISSION always brings the user to the app selection screen. https://developer.android.com/about/versions/11/privacy/permissions#manage_overlay This is highly confusing behaviour from the system, so let’s add an instruction before navigating to the settings menu.
This commit is contained in:
@@ -2,6 +2,7 @@ package org.schabi.newpipe.util;
|
|||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.app.AlertDialog;
|
||||||
import android.content.ActivityNotFoundException;
|
import android.content.ActivityNotFoundException;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -9,6 +10,7 @@ import android.content.pm.PackageManager;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
import android.text.Html;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.RequiresApi;
|
import androidx.annotation.RequiresApi;
|
||||||
@@ -113,14 +115,47 @@ public final class PermissionHelper {
|
|||||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
@RequiresApi(api = Build.VERSION_CODES.M)
|
||||||
public static boolean checkSystemAlertWindowPermission(final Context context) {
|
public static boolean checkSystemAlertWindowPermission(final Context context) {
|
||||||
if (!Settings.canDrawOverlays(context)) {
|
if (!Settings.canDrawOverlays(context)) {
|
||||||
final Intent i = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) {
|
||||||
Uri.parse("package:" + context.getPackageName()));
|
final Intent i = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
|
||||||
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
Uri.parse("package:" + context.getPackageName()));
|
||||||
try {
|
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
context.startActivity(i);
|
try {
|
||||||
} catch (final ActivityNotFoundException ignored) {
|
context.startActivity(i);
|
||||||
|
} catch (final ActivityNotFoundException ignored) {
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
// from Android R the ACTION_MANAGE_OVERLAY_PERMISSION will only point to the menu,
|
||||||
|
// so let’s add a dialog that points the user to the right setting.
|
||||||
|
} else {
|
||||||
|
final String appName = context.getApplicationInfo()
|
||||||
|
.loadLabel(context.getPackageManager()).toString();
|
||||||
|
final String title = context.getString(R.string.permission_display_over_apps);
|
||||||
|
final String permissionName =
|
||||||
|
context.getString(R.string.permission_display_over_apps_permission_name);
|
||||||
|
final String appNameItalic = "<i>" + appName + "</i>";
|
||||||
|
final String permissionNameItalic = "<i>" + permissionName + "</i>";
|
||||||
|
final String message =
|
||||||
|
context.getString(R.string.permission_display_over_apps_message,
|
||||||
|
appNameItalic,
|
||||||
|
permissionNameItalic
|
||||||
|
);
|
||||||
|
new AlertDialog.Builder(context)
|
||||||
|
.setTitle(title)
|
||||||
|
.setMessage(Html.fromHtml(message, Html.FROM_HTML_MODE_COMPACT))
|
||||||
|
.setPositiveButton("OK", (dialog, which) -> {
|
||||||
|
// we don’t need the package name here, since it won’t do anything on >R
|
||||||
|
final Intent intent =
|
||||||
|
new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
|
||||||
|
try {
|
||||||
|
context.startActivity(intent);
|
||||||
|
} catch (final ActivityNotFoundException ignored) {
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.setCancelable(true)
|
||||||
|
.show();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -257,6 +257,8 @@
|
|||||||
<string name="restore_defaults">Restore defaults</string>
|
<string name="restore_defaults">Restore defaults</string>
|
||||||
<string name="restore_defaults_confirmation">Do you want to restore defaults?</string>
|
<string name="restore_defaults_confirmation">Do you want to restore defaults?</string>
|
||||||
<string name="permission_display_over_apps">Give permission to display over other apps</string>
|
<string name="permission_display_over_apps">Give permission to display over other apps</string>
|
||||||
|
<string name="permission_display_over_apps_message">In order to use the Popup Player, please select %1$s in the following Android settings menu and enable %2$s.</string>
|
||||||
|
<string name="permission_display_over_apps_permission_name">“Allow display over other apps”</string>
|
||||||
<!-- error activity -->
|
<!-- error activity -->
|
||||||
<string name="error_report_notification_title">NewPipe encountered an error, tap to report</string>
|
<string name="error_report_notification_title">NewPipe encountered an error, tap to report</string>
|
||||||
<string name="error_report_notification_toast">An error occurred, see the notification</string>
|
<string name="error_report_notification_toast">An error occurred, see the notification</string>
|
||||||
|
Reference in New Issue
Block a user