A touch of the view that is always displayed on the screen

I have an idea that it is always on the screen (compared to other applications), I do not want to receive touch events and how to pass them on.

Code from the current one Service

:

    WindowManager.LayoutParams localLayoutParams = new WindowManager.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.MATCH_PARENT,
            WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
            WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,  
            PixelFormat.TRANSLUCENT);

    v.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            Toast.makeText(getApplicationContext(), "view touched", Toast.LENGTH_SHORT).show();
            return false;
        }
    });

    WindowManager localWindowManager = (WindowManager)getSystemService("window");
    localWindowManager.addView(v, localLayoutParams);

      

I am currently not getting touches.

+3


source to share


2 answers


You want to declare your view like TYPE_SYSTEM_ALERT

below:

WindowManager.LayoutParams params =
        new WindowManager.LayoutParams(width, height, x, y,
                WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                        | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
                PixelFormat.TRANSLUCENT);
params.gravity = Gravity.LEFT | Gravity.TOP;

      

Thus, it will only respond to touches of the view itself.

This code comes from a working task switcher that I developed. I didn't use FLAG_WATCH_OUTSIDE_TOUCH

it as it was causing me problems when interacting with other windows under my overlay.


As far as transferring applications to other applications is concerned, this is no longer possible because it poses a security risk.



I recently collected a few details on the same question that you may find interesting:

Also an interesting library mentioned by Edward Jezisek is StandOut from pingpongboss:

Since it is open source, you can go through the code to figure out what it does.

+5


source


I don't know why, but WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY

it makes your opinion insensitive.

Use WindowManager.LayoutParams.TYPE_PHONE

instead.



UPDATE:

I forgot one thing. If you install only WindowManager.LayoutParams.TYPE_PHONE

, the other app View

will not be affected. So add a flag WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE

.

0


source







All Articles