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

前端 未结 3 873
孤城傲影
孤城傲影 2020-12-05 16:58

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

相关标签:
3条回答
  • 2020-12-05 17:08

    Check this question and the answer:

    SYSTEM_ALERT_WINDOW - How to get this permission automatically on Android 6.0 and targetSdkVersion 23

    "Every app that requests the SYSTEM_ALERT_WINDOW permission and that is installed through the Play Store (version 6.0.5 or higher is required), will have granted the permission automatically."

    0 讨论(0)
  • 2020-12-05 17:16

    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);
    }
    
    0 讨论(0)
  • 2020-12-05 17:23
    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"></uses-permission>
    
    0 讨论(0)
提交回复
热议问题