从服务接收触摸事件(解决方案?) [英] Receiving Touch Events from a Service (Solution?)

查看:19
本文介绍了从服务接收触摸事件(解决方案?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,早些时候我发布了一个关于从服务接收触摸事件的问题(显然没有人知道答案).

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".

这是什么意思,如何在代码中实现?

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"

推荐答案

我使用这样的代码.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆