Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Overlay Windows

Overlay Windows

Droid Up 4.0 , 2017 talk about SYSTEM_ALERT_WINDOW and persistent overlay windows

Merab Tato Kutalia

January 29, 2017
Tweet

More Decks by Merab Tato Kutalia

Other Decks in Programming

Transcript

  1. SYSTEM_ALERT_WINDOW • Settings -> Apps -> Draw over other apps

    below 6.0 OR new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + packageName));
  2. Service Class • extend service • inflate or use custom

    / compound views • add to window manager service getSystemService(Context.WINDOW_SERVICE) • service stops immediately after activity destroy
  3. persistent service • return START_STICKY; always • and startForeground(int FOREGROUND_ID,

    Notification notification); those parameters allow to stay service alive and no matter what will persist over the top of apps // this will cause to show notification in status bar as long as the service retains. you can set pendingIntent to bind some actions on it
  4. some things to know we should pass WindowManager.LayoutParams along the

    actual view to the window manager service. WindowManager.LayoutParams windowLayoutParams = new WindowManager.LayoutParams(
 CANVAS_WIDTH,
 CANVAS_HEIGHT,
 WindowManager.LayoutParams.TYPE_PHONE,
 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
 PixelFormat.TRANSLUCENT);
 windowLayoutParams.gravity = Gravity.BOTTOM | Gravity.END;
 with incorrect parameters, service may block touch events for lower app in view hierarchy (because our service is on top), even keyboard will not work. https://developer.android.com/reference/android/view/ WindowManager.LayoutParams.html