I need to get DrawOverlays permission from my bound service. I am starting the activity - Settings.ACTION_MANAGE_OVERLAY_PERMISSION
provided by Android, to open the settings activity for the user, to give permission.
The problem is as soon as the activity opens the android shuts down my service. And as service cannot start an activity, as a result, the user needs to re-open the application which binds to the service after giving permission.
I am trying to first start another activity (Dialog Activity) and then get the dialog activity to open the settings activity screen. Still, the service is shutting down.
I also tried to bind the dialog activity to the service in hope to keep the service active but it results, first in shutdown, leaving the previous client and then start up with the new client i.e. dialog activity.
I am opening the activity from service like this.
if (!Settings.canDrawOverlays(nextGenPrintingService)) {
Log.i(Constants.TAG, "Requesting Permission");
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.parse("package:" +myService.getApplicationContext().getPackageName()));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
myService.startActivity(intent);
} else {
Log.i(Constants.TAG, "Permission already available");
}
The service is a bind service which returns a messenger contract in onBind()
function.
The service is started from other application using
Intent intent = new Intent();
intent.setClassName(Constants.SERVICE_PACKAGE, Constants.SERVICE_CLASS);
context.bindService(intent,
serviceConnection, Context.BIND_AUTO_CREATE);
I need to keep my service running while the settings screen is open for the user to give permission and then comeback successfully to the previous task in the service.