TheUnreal
TheUnreal

Reputation: 24472

Settings.canDrawOverlays for API < 23

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?

Upvotes: 9

Views: 5104

Answers (1)

Vrajesh Hirani
Vrajesh Hirani

Reputation: 139

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

Upvotes: 3

Related Questions