接收触摸事件从一个服务(解决方案?) [英] Receiving Touch Events from a Service (Solution?)
问题描述
所以,我早些时候发布了有关问题,从服务接收触摸事件(显然没有人知道答案)。
So, earlier I posted a question about receiving touch events from a service (apparently no one knows the answer).
在试图找出自己好几个小时,我放弃了,决定到电子邮件被称为RubberBigPepper开发。我问他是怎么做到的在他的应用程序的音量控制,他立即回答 TYPE_SYSTEM_ALERT窗口
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".
这是什么意思,以及它如何在code来实现?
What does this mean, and how can it be implemented in code?
编辑:
我用下面的方法:
getWindow().addFlags(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
和窗口未能接收触摸事件。
and the window failed to receive touch events.
我给他有关这个问题,以及,他说:使用WindowService添加你的窗口
I emailed him about this as well and he says: "Use the WindowService to add your window"
推荐答案
我用code这样的。
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);
和不要忘了使用,权限
这篇关于接收触摸事件从一个服务(解决方案?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!