Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
592 views
in Technique[技术] by (71.8m points)

android - 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...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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);
}  

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...