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...
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);
}
Add below code in your manifest
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
If you are using device which OS is more than 6.0 , please follow below steps
Go to Setting --> Select Apps ---> again select setting icon in Apps ---> select draw over other apps
Select your application and enable draw over other apps permition
Android "Screen Overlay Detected" message if user is trying to grant a permission when a notification is showing
You don't have to enable the screen overlay permission instead before asking for permission, Show your Dialog box explaining the user why you need the permission and requesting them to accept the permission. if user chooses no don't show the permission dialog. else show him the permission dialog. This helps you to avoid the screen overlay permission.
You have to leave your activity in order to get permission to draw your screen above some other activities. That is something you cannot avoid.
In order to do that, you have to visit Settings via ACTION_MANAGE_OVERLAY_PERMISSION
intent. Since you would like to have an user-friendly app, at the moment you need to ask for such permission, fire some dialog with explanation why you need that and with option for to accept and decline your requirement. On accept, fire the intent and start activity.