Daryl
Daryl

Reputation: 1

I can't allow overlay permission for my app

I can't allow the permission draw over other apps. It shows me the window to allow the permission but I can't toggle the switch, it's disabled. I checked other answer and its not helping me I used the same solution that the other discussions have but its not working.

here: screen shot of the disabled swtich for permission

here's my code:

when button is clicked launchMainservice is called

 btntest.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                hours = hours*3600000;
                mins = mins*60000;
                duration = hours+mins;
                Toast.makeText(Main2Activity.this,"duration: "+duration,LENGTH_LONG).show();
                StartService(duration);
                launchMainService();
                btntest.setClickable(false);
            }
        });

launchMainService():

 public void launchMainService() {
        if (Settings.canDrawOverlays(this)) {

            Toast.makeText(this,"service is working",Toast.LENGTH_LONG).show();
            Intent svc = new Intent(this, Service2.class);
            startService(svc);
        }
        else {


            Toast.makeText(this,"check permission",Toast.LENGTH_LONG).show();
            checkDrawOverlayPermission();
        }

    }

    public final static int REQUEST_CODE = 10101;

    public void checkDrawOverlayPermission() {


        if (!Settings.canDrawOverlays(this)) {

            Toast.makeText(this,"setting another permission",Toast.LENGTH_LONG).show();

            Intent intent123 = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName()));
            startActivityForResult(intent123, REQUEST_CODE);
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode,  Intent data) {


        if (requestCode == REQUEST_CODE) {
            Toast.makeText(this,"request code received",Toast.LENGTH_LONG).show();
            // Double-check that the user granted it, and didn't just dismiss the request
            if (Settings.canDrawOverlays(this)) {


                launchMainService();
            }
            else {
                Toast.makeText(this, "Sorry. Can't draw overlays without permission...", Toast.LENGTH_SHORT).show();
            }
        }
        Toast.makeText(this,"failed to receive request code",Toast.LENGTH_LONG).show();
    }

Upvotes: 0

Views: 1629

Answers (1)

Adam
Adam

Reputation: 11

For future generations searching this, I ran into the same issue. The problem was that I had unthinkingly requested the name of the permission, Manifest.permission.SYSTEM_ALERT_WINDOW, and not the value, android.permission.SYSTEM_ALERT_WINDOW. Since the manifest wasn't posted here as well, it's possible this was the same problem OP had.

Upvotes: 1

Related Questions