Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Settings.canDrawOverlays(context) returns false on Android Oreo

Manifest:

<uses-permission android:name="android.permission.SYSTEM_OVERLAY_WINDOW" />
<uses-permission android:name="android.permission.ACTION_MANAGE_OVERLAY_PERMISSION" />

Code activity.onCreate():

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && BuildConfig.DEBUG) {
        if (!Settings.canDrawOverlays(this)) {
            Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
                    Uri.parse("package:" + getPackageName()));
            startActivityForResult(intent, OVERLAY_PERMISSION_REQ_CODE);
        }
    }

Problem: Settings.canDrawOverlays(this) returns false even so the permission has been already granted. Hasn't happened before update Pixel to Oreo.

Android version: 8.0.0

I've tried to update build tools: to 26.0.1 and target and compileSdk to 26. It helped on the first launch :after toggling on it returns true, but next time I launch application it returns false again.

like image 620
Happy Dev Avatar asked Oct 30 '22 02:10

Happy Dev


1 Answers

The problem was in Android Oreo itself.

After I've installed security patch it disappeared.

Solution: Install latest security patch.

like image 131
Happy Dev Avatar answered Nov 15 '22 07:11

Happy Dev