Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permission denied #1

Open
sedatkilinc opened this issue Feb 7, 2018 · 1 comment
Open

Permission denied #1

sedatkilinc opened this issue Feb 7, 2018 · 1 comment

Comments

@sedatkilinc
Copy link

Hi,

I've tried to use your service in my app (min SDK 19), but I get an exception:
Caused by: android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@51664d3 -- permission denied for this window type

I'm using following permission:
android.permission.SYSTEM_ALERT_WINDOW
android.permission.ACTION_MANAGE_OVERLAY_PERMISSION

@JanStorm
Copy link

You need to request the permission from the user. I solved this issue using the following code in my MainActivity:

public final static int REQUEST_CODE = -1010101;

public void checkDrawOverlayPermission() {
	if (Build.VERSION.SDK_INT > 23 && !Settings.canDrawOverlays(this)) {
		Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
				Uri.parse("package:" + getPackageName()));
		startActivityForResult(intent, REQUEST_CODE);
	}else
		enableService();
}

@Override
protected void onActivityResult(int requestCode, int resultCode,  Intent data) {
	if (requestCode == REQUEST_CODE) {
       		if (Build.VERSION.SDK_INT > 23 && Settings.canDrawOverlays(this)) {
			enableService();
			Toast.makeText(this, "Access granted",Toast.LENGTH_SHORT).show();
		}
	}
}

See https://stackoverflow.com/questions/7569937/unable-to-add-window-android-view-viewrootw44da9bc0-permission-denied-for-t

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants