0

this drives me crazy.... since my Smartphone has API > 23 my youtube overlay doesnt work anymore.... so i implemented all the neccessary stuff. Now, my app asks for the permission to draw overlays (SYSTEM_ALERT_WINDOW) and if i debug my app then i see that the permission is granted. But if i start the overlay i get this error msg:

AndroidRuntime: FATAL EXCEPTION: main java.lang.RuntimeException: Unable to create service ...: android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@479d57e -- permission denied for window type 2002

Permissions in Manifest are these:

<uses-permission android:name="android.permission.ACTION_MANAGE_OVERLAY_PERMISSION" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

i ask for permission:

Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName()));
startActivityForResult(intent, MainActivity.PERMISSIONS_REQUEST_SYSTEM_ALERT_WINDOW);

i check the permission like this:

if (Settings.canDrawOverlays(this)) {
   permissionShowYoutubeOverlayIsOK = true;
}

So, what the hell is wrong here ??

any help is appreciated!!!

bye phil

just4phil
  • 25
  • 1
  • 5

2 Answers2

0

According to the documentation on Android 8.0 Behavior Changes for apps targeting Android 8.0:

Apps that use the SYSTEM_ALERT_WINDOW permission can no longer use the following window types to display alert windows above other apps and system windows:

TYPE_PHONE, TYPE_PRIORITY_PHONE, TYPE_SYSTEM_ALERT, TYPE_SYSTEM_OVERLAY, TYPE_SYSTEM_ERROR

Instead, apps must use a new window type called TYPE_APPLICATION_OVERLAY

So you have to lower TargetSDK or use newer TYPE_xxxxx

emandt
  • 2,547
  • 2
  • 16
  • 20
0

Thanks! that really helped :) but there have been some more steps to do:

  1. change to TYPE_APPLICATION_OVERLAY like you described

  2. add permission:

<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

see: Permission Denial: startForeground requires android.permission.FOREGROUND_SERVICE

  1. new notification channel required

    see: startForeground fail after upgrade to Android 8.1

now it finally runs without issues :) THANK YOU!!

Community
  • 1
  • 1
just4phil
  • 25
  • 1
  • 5