Since I can use Settings.canDrawOverlays
to check if the user granted this permission on API >= 23, how I can check if the user have it on older APIS?
Does this permission is automically granted on API < 23 and no need to check for it?
Currently, I start my service only on API 23+ after the permission are granted.
@SuppressLint("NewApi")
public void checkDrawOverlayPermission() {
if(Build.VERSION.SDK_INT >= 23) {
/** check if we already have permission to draw over other apps */
if (!Settings.canDrawOverlays(this)) {
/** if not construct intent to request permission */
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.parse("package:" + getPackageName()));
/** request permission via start activity for result */
startActivityForResult(intent, REQUEST_CODE);
} else {
startService(new Intent(this, ChatHeadService.class));
}
}
}
But what if the user is on API <= 22? How I can make sure the application wont crash and my service will start?
Overlay permission is only required for Marshmallow (API 23) and above. In previous APIs this permission is provided by default.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With