title: permission denied for window type 2038 - Android TV
body: <p>I am attempting to develop floating "widgets" for an android TV (android 8) and every time I try to run the app I'm prompted with:</p>
  
  <pre><code>E/AndroidRuntime: FATAL EXCEPTION: main
  Process: com.example.floatingwidget2020, PID: 11548
  java.lang.RuntimeException: Unable to create service com.example.floatingwidget2020.FloatingWindow: android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@e7b96bd -- permission denied for window type 2038
      at android.app.ActivityThread.handleCreateService(ActivityThread.java:3414)
      at android.app.ActivityThread.-wrap4(Unknown Source:0)
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1683)
      at android.os.Handler.dispatchMessage(Handler.java:105)
      at android.os.Looper.loop(Looper.java:164)
      at android.app.ActivityThread.main(ActivityThread.java:6541)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
   Caused by: android.view.WindowManager$BadTokenException: Unable to add window android.view.ViewRootImpl$W@e7b96bd -- permission denied for window type 2038
      at android.view.ViewRootImpl.setView(ViewRootImpl.java:789)
      at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:356)
      at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:92)
      at com.example.floatingwidget2020.FloatingWindow.onCreate(FloatingWindow.java:57)
      at android.app.ActivityThread.handleCreateService(ActivityThread.java:3404)
      at android.app.ActivityThread.-wrap4(Unknown Source:0) 
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1683) 
      at android.os.Handler.dispatchMessage(Handler.java:105) 
      at android.os.Looper.loop(Looper.java:164) 
      at android.app.ActivityThread.main(ActivityThread.java:6541) 
      at java.lang.reflect.Method.invoke(Native Method) 
      at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767) 
  </code></pre>
  
  <p>When I initially run the emulator the console prompts with:</p>
  
  <pre><code>E/eglCodecCommon: glUtilsParamSize: unknow param 0x000082da
  glUtilsParamSize: unknow param 0x000082da
  </code></pre>
  
  <p>Snippet of what I believe to be resulting in the issue:</p>
  
  <pre><code>final WindowManager.LayoutParams parameters = new WindowManager.LayoutParams(400, 150, WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, PixelFormat.TRANSLUCENT);
  </code></pre>
  
  <p>and in AndroidManifest.xml:</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/&gt;
  </code></pre>
  
  <p>When I change flag to WindowManager.LayoutParams.TYPE_PHONE it works fine on phone, but no go on android TV.</p>
  
  <p>Any help is appreciated!</p>