Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically grant the "draw over other apps" permission in android?

Tags:

java

android

How can I programmatically grant the permission in Settings -> Apps -> Draw over other apps in Android? I want to use system alert window but unable to in Android Marshmallow without forcing the user to go through the Settings app and grant the permission first.

like image 609
Anil Ranga Avatar asked Nov 01 '16 06:11

Anil Ranga


2 Answers

You can check and ask for overlay permission to draw over other apps using this

if (!Settings.canDrawOverlays(this)) {
    Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName()));
    startActivityForResult(intent, 0);
}
like image 65
Shashank Udupa Avatar answered Oct 22 '22 09:10

Shashank Udupa


if (!Settings.canDrawOverlays(this)) {
    Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, 
    Uri.parse("package:" + getPackageName()));
    startActivityForResult(intent, 0);
}
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
like image 40
sumit baflipara Avatar answered Oct 22 '22 10:10

sumit baflipara