Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable screen overlay permission by default

How can I enable screen overlay permission by default while install application.

Now I facing some problem, when capture image asking run time permission some device not allow the permission it open screen overlay settings dialog. at user point of view, they don't know why the dialog showing and what they do.

when open the overlay settings screen some of applications automatically enable the screen overlay permission.

Below I use the code.

 if (!Settings.canDrawOverlays(this)) {
        Intent myIntent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
        startActivityForResult(myIntent, 101);
 }  

This code directly open the overlay settings screen. their showing list of all application.

My requirement is showing permission specific application or enable overlay permission with out user interaction.

do needfull...

like image 988
Rajesh J Avatar asked Oct 31 '16 05:10

Rajesh J


People also ask

Why can't I turn on screen overlay?

Go to Settings and tap on Advanced features. One-handed operations will be the first option at the top. Tap on it and toggle off one-handed operations at the bottom. Now, try to use the app that gave you the screen overlay error.

What is the overlay permission?

When an app asks for permission to display overlays, the user will be sent to the general 'Display over other apps' permission list, so they'll have to find the app in the list and select it there. Not a big deal, but it does add a bit of friction that may prevent users from blindly giving malware access to overlays.


1 Answers

Send your package name inside the intent, as mentioned in the documentation.

Input: Optionally, the Intent's data URI can specify the application package name to directly invoke the management GUI specific to the package name. For example "package:com.my.app".

So, do something like this:

if (!Settings.canDrawOverlays(this)) {
    int REQUEST_CODE = 101;
    Intent myIntent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
    myIntent.setData(Uri.parse("package:" + getPackageName()));
    startActivityForResult(myIntent, REQUEST_CODE);
}  
like image 137
MohanadMohie Avatar answered Oct 13 '22 01:10

MohanadMohie