2

I have an overlay view (LinearLayout) added to WindowManager with following params set:

private void setWindowParams(WindowManager.LayoutParams params) {
    params.height = WindowManager.LayoutParams.WRAP_CONTENT;
    params.width = WindowManager.LayoutParams.WRAP_CONTENT;
    params.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
    params.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE 
        | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
        | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
    params.format = PixelFormat.TRANSLUCENT;
    params.gravity = Gravity.CENTER;
}

This LinearLayout contains three buttons "HOME", "RECENTS", "BACK"

I have implemented onKeyEvent() to remove this overlay view from window manager when phone's back button is pressed.

When back button is pressed from my overlay layout, i call my accessibility service and it works normally. Now when I press my phone's back button, my overlay view stays. Because it is not receiving key events since I had WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE this flag set in params.

But when I didn't set this flag, pressing back button from overlay just hides the overlay itself rather than performing back on the activity underneath it.

I want my overlay to hide on pressing phone's back button. And also to perform back button functionality on pressing back button from my overlay.

Is there any way to differentiate actual button press and software triggered button press using performGlobalAction(MyAccessibilityService.ACTION_BACK) ? Any suggestions on how to implement this properly?

rehman_00001
  • 1,299
  • 1
  • 15
  • 28

1 Answers1

0

you can't do that because Context of the Dialog Will Be Destroy when Activity is Killed , you can use WindowManager

  • Thanks for ur response. I mentioned that in my question as second approach. Still it did not work completely – rehman_00001 Oct 05 '16 at 03:04
  • just use [removeview](https://developer.android.com/reference/android/view/ViewManager.html#removeView(android.view.View)) to remove this dialog – user2423314 Oct 06 '16 at 01:19
  • 1
    Hope I'm clear with my question. I knew using removeView() will remove it from window. But just want to know how to call it when system's back button is pressed without affecting my overlay's back button – rehman_00001 Oct 08 '16 at 08:37