Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MANAGE_OVERLAY_PERMISSION - activity not found exception

I'm getting following exception:

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.settings.action.MANAGE_OVERLAY_PERMISSION dat=package:com.my.app }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1816)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1525)
at android.app.Activity.startActivityForResult(Activity.java:4265)

This happened in an app that's already a few years old and is working flawlessly. Now I got this exception for an android 7 device, model ZUK Z1. Any ideas? Seems like a problem with the rom. Does this rom offer an alternative way to get overlay drawing permissions?

Edit - here's the function I use to get permissions

public static void checkOverlayPermission(Activity activity)
{
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.canDrawOverlays(activity))
    {
        Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + activity.getPackageName()));
        activity.startActivityForResult(intent, BaseDef.OVERLAY_PERMISSION_REQ_CODE);
    }
}
like image 384
prom85 Avatar asked Nov 07 '22 22:11

prom85


1 Answers

Try this one.This is working for me. It may help you

if (!Settings.canDrawOverlays(this)) {
                Intent localIntent = new Intent("android.settings.action.MANAGE_OVERLAY_PERMISSION");
                localIntent.setData(Uri.parse("package:" + getPackageName()));
                localIntent.setFlags(268435456);
                startActivity(localIntent);
            }

Try this if your rom is the issue

Basically you can't just check all rom which have issues with settings. The code above works fine in android N as well. I tested this myself.

What you can do is put your code inside a try catch block and when you enters the catch block show user a dialog which asks him to give overlay permission manually instead taking him directly to the settings page.

There are some roms basically the custom roms which have issues with some system settings so this is the best approach you can use to tackle these situations.

like image 145
UltimateDevil Avatar answered Nov 15 '22 12:11

UltimateDevil