forked from Github/cordova-plugin-run-in-background
Add fix for moveToForeground. Requires new permission for Android 10
This commit is contained in:
@@ -34,6 +34,7 @@ import android.content.pm.PackageManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.PowerManager;
|
||||
import android.provider.Settings;
|
||||
import android.view.View;
|
||||
|
||||
import org.apache.cordova.CallbackContext;
|
||||
@@ -109,6 +110,9 @@ public class BackgroundModeExt extends CordovaPlugin {
|
||||
case "foreground":
|
||||
moveToForeground();
|
||||
break;
|
||||
case "requestTopPermissions":
|
||||
requestTopPermissions();
|
||||
break;
|
||||
case "tasklist":
|
||||
excludeFromTaskList();
|
||||
break;
|
||||
@@ -249,6 +253,20 @@ public class BackgroundModeExt extends CordovaPlugin {
|
||||
callback.sendPluginResult(res);
|
||||
}
|
||||
|
||||
private void requestTopPermissions() {
|
||||
if (SDK_INT >= M) {
|
||||
|
||||
Activity activity = cordova.getActivity();
|
||||
if (Settings.canDrawOverlays(activity.getApplicationContext())) {
|
||||
return;
|
||||
}
|
||||
|
||||
String pkgName = activity.getPackageName();
|
||||
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + pkgName));
|
||||
activity.startActivity(intent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the system settings dialog where the user can tweak or turn off any
|
||||
* custom app start settings added by the manufacturer if available.
|
||||
|
||||
Reference in New Issue
Block a user