Santacrab
Santacrab

Reputation: 3195

"Draw over other apps" change listener?

In my application I have the necessity to know when the user grants the "Draw over other apps" permission. Is there a way to know it? Since I can only send the user to the settings page to enable it using the Settings.ACTION_MANAGE_OVERLAY_PERMISSION intent action, I'd expect a system broadcast or something like that.

Upvotes: 6

Views: 1272

Answers (1)

Mattia Maestrini
Mattia Maestrini

Reputation: 32790

Unfortunately there isn't a system broadcast, but you can use canDrawOverlays (Context context):

An app can use this method to check if it is currently allowed to draw on top of other apps. In order to be allowed to do so, an app must first declare the SYSTEM_ALERT_WINDOW permission in its manifest. If it is currently disallowed, it can prompt the user to grant it this capability through a management UI by sending an Intent with action ACTION_MANAGE_OVERLAY_PERMISSION.

You can check it directly in your onActivityResult:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_CODE) {
        if (Settings.canDrawOverlays(this)) {
            //Permission is granted
        }
    }
}

Upvotes: 2

Related Questions