6

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);
    }
}
7
  • what version you running your app that works before. Remember after Android 6.0 Marshmallow, your app need to request permissions(some) during run time. You can no longer request permission on manifest.
    – kggoh
    May 12, 2017 at 6:05
  • All from android 5 to 7. And if I would not start an activity (like before android 6) I would not get the exception. I added the code above to show you what I do
    – prom85
    May 12, 2017 at 6:08
  • Hey @prom85 did you find any solution of this question Sep 28, 2017 at 5:00
  • @UltimateDevil I guess we'll never know
    – Denny
    Sep 21, 2018 at 17:54
  • Hi Guys I am having the same issue but on Android TV. Is there a way to get it to work on TV?
    – SKG
    Jan 10, 2019 at 0:31

2 Answers 2

1

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.

2
  • 2
    not sure why you havelocalIntent.setFlags(268435456); I omitted it and everything works great
    – CrandellWS
    Apr 12, 2018 at 18:59
  • 1
    This is exactly what's in Settings.ACTION_MANAGE_OVERLAY_PERMISSION. Downvote. Bad practice to manually type in the Action Intent.
    – ralphgabb
    Jun 18, 2019 at 3:03
0

What worked for me:

            var intent = new Intent(Android.Provider.Settings.ActionManageOverlayPermission);
            intent.SetData(Android.Net.Uri.FromParts("package", PackageName, null));
            StartActivity(intent);

This is in Xamarin tho!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.