I keep receiving this exception, when i try to create a system wide overlay using a WindowManager and the corresponding permission:
Unable to add window android.view.ViewRootImpl$W@6b3c898 -- the specified window type is not valid
My Code (run from my activities onCreate):
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, CHECK_OVERLAY_PERMISSION_REQUEST_CODE);
}
}
if(Build.VERSION.SDK_INT >=23 && Settings.canDrawOverlays(this)) {
WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
PixelFormat.TRANSLUCENT
);
View overlay = ((LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE)).inflate(R.layout.overlay_playback_controls, null);
//overlay.setOnClickListener(this);
windowManager.addView(overlay, layoutParams);
}
And if needed, heres the corresponding xml-layout file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Test!!!"
/>
</LinearLayout>
I have already tried all hints from this post (including the linked one), but still have no idea what the problem is: Unable to add window android.view.ViewRoot$W@44da9bc0 -- permission denied for this window type