Android 10 permission

This commit is contained in:
Milos Kozak 2020-02-03 18:23:20 +01:00
parent b5a64f4d85
commit db47cd6fe9
4 changed files with 23 additions and 0 deletions

View file

@ -147,6 +147,7 @@ public class MainActivity extends NoSplashAppCompatActivity {
if (Config.PUMPDRIVERS) {
AndroidPermission.notifyForLocationPermissions(this);
AndroidPermission.notifyForSMSPermissions(this);
AndroidPermission.notifyForSystemWindowPermissions(this);
}
}
@ -245,6 +246,7 @@ public class MainActivity extends NoSplashAppCompatActivity {
case AndroidPermission.CASE_SMS:
case AndroidPermission.CASE_BATTERY:
case AndroidPermission.CASE_PHONE_STATE:
case AndroidPermission.CASE_SYSTEM_WINDOW:
break;
}
}

View file

@ -78,6 +78,7 @@ public class Notification {
public static final int USERMESSAGE = 53;
public static final int OVER_24H_TIME_CHANGE_REQUESTED = 54;
public static final int INVALID_VERSION = 55;
public static final int PERMISSION_SYSTEM_WINDOW = 56;
public int id;

View file

@ -32,6 +32,7 @@ public class AndroidPermission {
public static final int CASE_LOCATION = 0x3;
public static final int CASE_BATTERY = 0x4;
public static final int CASE_PHONE_STATE = 0x5;
public static final int CASE_SYSTEM_WINDOW = 0x6;
private static boolean permission_battery_optimization_failed = false;
@ -130,4 +131,22 @@ public class AndroidPermission {
} else
RxBus.INSTANCE.send(new EventDismissNotification(Notification.PERMISSION_LOCATION));
}
public static synchronized void notifyForSystemWindowPermissions(Activity activity) {
if (!Settings.canDrawOverlays(activity)) {
NotificationWithAction notification = new NotificationWithAction(Notification.PERMISSION_SYSTEM_WINDOW, MainApp.gs(R.string.needsystemwindowpermission), Notification.URGENT);
notification.action(R.string.request, () -> {
// Check if Android Q or higher
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) {
// Show alert dialog to the user saying a separate permission is needed
// Launch the settings activity if the user prefers
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.parse("package:" + activity.getPackageName()));
activity.startActivity(intent);
}
});
RxBus.INSTANCE.send(new EventNewNotification(notification));
} else
RxBus.INSTANCE.send(new EventDismissNotification(Notification.PERMISSION_SYSTEM_WINDOW));
}
}

View file

@ -1102,6 +1102,7 @@
<string name="startobjective">Start your first objective</string>
<string name="permission">Permission</string>
<string name="askforpermission">Ask for permission</string>
<string name="needsystemwindowpermission">Application needs system window permission for notifications</string>
<string name="needlocationpermission">Application needs location permission for BT scan</string>
<string name="needstoragepermission">Application needs storage permission to be able store log files</string>
<string name="request">Request</string>