When we want to display an overlay window on the Phone screen in Android version 6 and above this exception will come. To fix this issue follwo below steps Check Manifest file with below permission Check Permission Granted for Android 6(Marshmallow and above devices) and above with below code Check Permision Request Result
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
public booleancheckOverLayPermission() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (!Settings.canDrawOverlays(this)) {
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, OVERLAY_PERMISSION_CODE);
return false;
}else
{
return true;
}
}else
{
return true;
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == OVERLAY_PERMISSION_CODE) {
if (Settings.canDrawOverlays(this)) {
// SYSTEM_ALERT_WINDOW permission not granted...
Intent serviceIntent = new Intent(Homepage.this, ChatHeadService.class);
serviceIntent.putExtra("removeUserId", friendId);
startService(serviceIntent);
} else {
Toast.makeText(MyProtector.getContext(), "ACTION_MANAGE_OVERLAY_PERMISSION Permission Denied", Toast.LENGTH_SHORT).show();
}
}
Key Points to remember while develop the Android Application.
What is Android?
How to find Android Device UDID or unique ID?
How do I check in SQLite whether a table exists?
Decompile APK Files: How to Get Source Code - RRutors Guide
Set Activity to Fullscreen Mode in Android - RRutors
How To Set Text Color Programmatically Android TextView?
How to convert DP to Pixel and Pixel to Dp?
What is "shared preferences" in Android ?
What is Application?
How to copy database from assets folder in android using kotlin
What is Intent? What is the difference between an implicit intent and an explicit intent?
How to start a new activity on button click
What is ANR in android?
Android Studio project R can't find
Permission denied for window type 2010 in Marshmallow device
Extract Date and Time from Long Type Variable - RRutors
How to save activity State in Android?
How do i load image from drawable folder in Jetpack Compose?
Fix Behavior Subclass BottomSheetBehavior Exception - RRutors
What is ANR? How to avoid and resolve it?
Fix Android Emulator Kill Error When Running Your App
What is NetworkOnMainThread Exception?
What are Android Versions available?
Fix Error: Use JsonReader.setLenient(true) for Malformed JSON
Emulator: emulator: ERROR: Can't find 'Linux version ' string in kernel image file: Andr
How to get a contact image using a phone number in android?
How to Generate signed apk with android studio
Symmetric vs Asymmetric Encryption in Android Server - RRutors
Check List for Generate Signed APK Android
Add Jar/Library Files as Dependency in Android Studio
ERR_ACCESS_DENIED in Android Webview with sdk 30
How to stop EditText focus at Activity startup in Android?
Open PDF in Google Drive with Intent in Android - RRutors
How to Use Deprecated Handler() in Android - RRutors Guide
How to get complete address from latitude and longitude?
How to validate email address in Android with Kotlin?
FCM Not Receiving Notifications in Android - RRutors
Fix Play Store Rejection Due to SMS Permission - RRutors
What is Context?