Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

android - 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).

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"

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...