We have been working on "Draw over other apps" permission to develop a cool function for our app on Marshmallow.
Our app's new feature worked perfectly with the very first installation of our app. We didn't have any issue with "Draw over other apps" permission.
However, our nightmare began when our app was erased and reinstalled or updated with a newer version. The new feature didn't work at all and there was no error message at all.
When we checked the status of "Draw over other apps" it was activated. It meant our new feature was supposed to work but it did not.
But once we refreshed "Draw over other apps" status from inactivated to activated even though it had already been "activated", a new feature worked again perfectly.
We don't think we can ask users to refresh "Draw over other apps" manually at every update or reinstallation.
Any help will be greatly appreciated. Anyone?
1.Activity - 2.Service(PopupWindow)
3.PermissionOverlay Activity
2.Service
public void runPopup() {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if(!Settings.canDrawOverlays(getBaseContext())) {
setOverlayPermission();
return;
}
}
// other working..
}
public void setOverlayPermission() {
Runnable myRunnable = new Runnable() {
@Override
public void run() {
new PermPermission(instance)
.setPermissionListener(hecpermissionlistener)
.setDeniedMessage("The necessary permissions!")
.setPermissions(android.Manifest.permission.SYSTEM_ALERT_WINDOW)
.check();
}
};
grantHandler.post(myRunnable);
}
3.PermissionOverlay Activity
public void requestPermissions(ArrayList<String> needPermissions) {
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.parse("package:" + packageName));
startActivityForResult(intent, REQ_CODE_REQUEST_SETTING);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case REQ_CODE_REQUEST_SETTING:
checkPermissions(true);
break;
default:
super.onActivityResult(requestCode, resultCode, data);
}
}