title: Android System overlay window
body: <p>I'm trying to create a system overlay. But I keep getting "permission denied". I'm using SDK version 23.</p>
  
  <p>My manifest file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.test" &gt;
  
  &lt;uses-permission android:name="android.permission.SYSTEM_OVERLAY_WINDOW" /&gt;
  
  &lt;application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/AppTheme" &gt;
      &lt;activity
          android:name=".activity.MainActivity"
          android:label="@string/app_name" &gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
  
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
  &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>The code I use to create the overlay:</p>
  
  <pre><code>    //mView = new HUDView(this);
      mButton = new Button(this);
      mButton.setText("Overlay button");
      mButton.setOnTouchListener(this);
  
      WindowManager.LayoutParams params = new WindowManager.LayoutParams(
              WindowManager.LayoutParams.WRAP_CONTENT,
              WindowManager.LayoutParams.WRAP_CONTENT,
              WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
              WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
              PixelFormat.TRANSLUCENT);
      params.gravity = Gravity.RIGHT | Gravity.TOP;
      params.setTitle("Load Average");
      WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
      wm.addView(mButton, params);
  </code></pre>