Receiving Touch Events from a Service (Solution?)

百般思念 提交于 2019-11-28 06:37:12

问题


So, earlier I posted a question about receiving touch events from a service (apparently no one knows the answer).

After trying to figure it out myself for hours, I gave up and decided to email a developer known as RubberBigPepper. I asked him how he did it in his app Volume control and he promptly responded "TYPE_SYSTEM_ALERT window".

What does this mean, and how can it be implemented in code?

EDIT:

I used the following method:

getWindow().addFlags(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);

and the window failed to receive touch events.

I emailed him about this as well and he says: "Use the WindowService to add your window"


回答1:


I use code like this.

int nFlags=WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL|WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;       
             m_cWM=(WindowManager)getSystemService(Context.WINDOW_SERVICE);
             WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.WRAP_CONTENT,WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
                nFlags,
                PixelFormat.TRANSLUCENT);
m_cWM.addView(YourViewClass, lp);

And don't forget about uses-permissions



来源:https://stackoverflow.com/questions/11322188/receiving-touch-events-from-a-service-solution

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!