Unable to add window android.view.ViewRoot$W@44da9bc0 -- permission denied for this window type
Try using this permission in AndroidManifest.
android.permission.SYSTEM_ALERT_WINDOW
on API >= 23 see
Android: Unable to add window. Permission denied for this window type
For what should be completely obvious reasons, ordinary Apps are not allowed to create arbitrary windows on top of the lock screen. What do you think I could do if I created a window on your lockscreen that could perfectly imitate the real lockscreen so you couldn't tell the difference?
The technical reason for your error is the use of the TYPE_KEYGUARD_DIALOG
flag - it requires android.permission.INTERNAL_SYSTEM_WINDOW
which is a signature-level permission. This means that only Apps signed with the same certificate as the creator of the permission can use it.
The creator of android.permission.INTERNAL_SYSTEM_WINDOW
is the Android system itself, so unless your App is part of the OS, you don't stand a chance.
There are well defined and well documented ways of notifying the user of information from the lockscreen. You can create customised notifications which show on the lockscreen and the user can interact with them.
Unable to add window -- permission denied for this window type
This question has been solved by myself
UPDATE
make sure you have added permission in the manifest.
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
put this on onCreate or whatever you want to askPermission()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.canDrawOverlays(this)) {
askPermission()
}
Method:
@TargetApi(23)
public void askPermission() {
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, SYSTEM_ALERT_WINDOW_PERMISSION);
}
Permission denied for window type 2002 in Android Studio
This is occurring because the targetSdkVersion in the example and your targetSdkVersion are different. Use the flag TYPE_APPLICATION_OVERLAY instead of TYPE_PHONE in WindowManager.LayoutParams:
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY
Unable to add window - windowmanager permission denied for this window type 2003 or 2006
I've solved the problem. We need some permissions when working with Android M and above. You can fix this problem with "draw over other apps" permission.
Add to manifest
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
WindowManager
windowManager = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);
surfaceView = new SurfaceView(this);
ViewGroup.LayoutParams layoutParams = new WindowManager.LayoutParams(1, 1,
Build.VERSION.SDK_INT < Build.VERSION_CODES.O ?
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY :
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
PixelFormat.TRANSLUCENT);
windowManager.addView(surfaceView, layoutParams);
surfaceView.getHolder().addCallback(this);
Add to your codes (onCreate)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (!Settings.canDrawOverlays(this)) {
Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, 0);
}
}
Android: permission denied for window type 2038 using TYPE_APPLICATION_OVERLAY
I had the exactly same issue. I guess you should differentiate the target (before and after Oreo)
int LAYOUT_FLAG;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
LAYOUT_FLAG = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
} else {
LAYOUT_FLAG = WindowManager.LayoutParams.TYPE_PHONE;
}
params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
LAYOUT_FLAG,
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
Related Topics
Viewpager.Setoffscreenpagelimit(0) Doesn't Work as Expected
Can Not Find a View With Findviewbyid()
Sending Message Through Whatsapp
How to Read Mms Data in Android
Httpclient Won't Import in Android Studio
Difference Between Fragmentpageradapter and Fragmentstatepageradapter
Cursorloader Usage Without Contentprovider
How to Record a Video in My Android App
Android Pick Images from Gallery
Onitemclicklistener Not Working in Listview
How to Disable Mobile Data on Android
Android.View.Inflateexception: Binary Xml File Line #12: Error Inflating Class ≪Unknown≫
How to Add a Border to the Top and Bottom of an Android View
Android 4.1: How to Check Notifications Are Disabled for the Application
How to Programmatically Tell If a Bluetooth Device Is Connected
Using Intent in an Android Application to Show Another Activity