Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Settings.canDrawOverlays for API < 23

Tags:

android

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?

like image 495
TheUnreal Avatar asked Oct 07 '16 07:10

TheUnreal


1 Answers

Overlay permission is only required for Marshmallow (API 23) and above. In previous APIs this permission is provided by default.

like image 65
Vrajesh Hirani Avatar answered Oct 17 '22 14:10

Vrajesh Hirani