mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-10 17:11:56 +01:00
Scroll Notification and Overlay permissions screens to GB automatically
This commit is contained in:
parent
77d0d545c8
commit
fc4fea35cd
@ -20,11 +20,14 @@ import android.Manifest;
|
|||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.NotificationManager;
|
import android.app.NotificationManager;
|
||||||
import android.content.ActivityNotFoundException;
|
import android.content.ActivityNotFoundException;
|
||||||
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.os.Bundle;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
@ -44,6 +47,7 @@ import java.util.Set;
|
|||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.BuildConfig;
|
import nodomain.freeyourgadget.gadgetbridge.BuildConfig;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.externalevents.NotificationListener;
|
||||||
|
|
||||||
public class PermissionsUtils {
|
public class PermissionsUtils {
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(PermissionsUtils.class);
|
private static final Logger LOG = LoggerFactory.getLogger(PermissionsUtils.class);
|
||||||
@ -244,9 +248,22 @@ public class PermissionsUtils {
|
|||||||
activity.getString(R.string.app_name),
|
activity.getString(R.string.app_name),
|
||||||
activity.getString(R.string.ok)))
|
activity.getString(R.string.ok)))
|
||||||
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
|
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
|
||||||
|
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP_MR1)
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
try {
|
try {
|
||||||
activity.startActivity(new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS"));
|
Intent intent;
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||||
|
intent = new Intent(Settings.ACTION_NOTIFICATION_LISTENER_DETAIL_SETTINGS);
|
||||||
|
intent.putExtra(Settings.EXTRA_NOTIFICATION_LISTENER_COMPONENT_NAME, new ComponentName(BuildConfig.APPLICATION_ID, NotificationListener.class.getName()).flattenToString());
|
||||||
|
} else {
|
||||||
|
intent = new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS);
|
||||||
|
}
|
||||||
|
String showArgs = BuildConfig.APPLICATION_ID + "/" + NotificationListener.class.getName();
|
||||||
|
intent.putExtra(":settings:fragment_args_key", showArgs);
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putString(":settings:fragment_args_key", showArgs);
|
||||||
|
intent.putExtra(":settings:show_fragment_args", bundle);
|
||||||
|
activity.startActivity(intent);
|
||||||
} catch (ActivityNotFoundException e) {
|
} catch (ActivityNotFoundException e) {
|
||||||
GB.toast(activity, "'Notification Listener Settings' activity not found", Toast.LENGTH_LONG, GB.ERROR);
|
GB.toast(activity, "'Notification Listener Settings' activity not found", Toast.LENGTH_LONG, GB.ERROR);
|
||||||
LOG.error("'Notification Listener Settings' activity not found");
|
LOG.error("'Notification Listener Settings' activity not found");
|
||||||
@ -283,7 +300,10 @@ public class PermissionsUtils {
|
|||||||
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
|
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
|
||||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
@RequiresApi(api = Build.VERSION_CODES.M)
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
Intent enableIntent = new Intent(android.provider.Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
|
Intent enableIntent = new Intent(
|
||||||
|
android.provider.Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
|
||||||
|
Uri.parse("package:" + BuildConfig.APPLICATION_ID)
|
||||||
|
);
|
||||||
activity.startActivity(enableIntent);
|
activity.startActivity(enableIntent);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user