Service Receiving Touch Events from all Activities on Phone?
I've seen applications that if you touch a certain part of the screen (i.e. very top left) they will launch an application. This can be done from the home screen, or any application on my screen. The best I can figure how they can do this is by having a service that receives all touch events, and th开发者_如何学运维en tests whether or not they are in the specified area? How would you do this? Can anyone point me in the right direction?
The best I can figure how they can do this is by having a service that receives all touch events, and then tests whether or not they are in the specified area?
No.
How would you do this?
A service cannot receive touch events, sorry.
Can anyone point me in the right direction?
I believe that the apps in question were exploiting a security hole that has since been closed.
Implement an onTouchListener
and check the view or coords that it returns. A service is just for controlling background activities using threads.
Edit:
Probably the best wasy to do this would be to override Activity.dispatchTouchEvent(TouchEvent event)
and use a loop to pick out the View
that was touched. For example.
@Override
dispathTouchEvent(MotionEvent event) {
ViewGroup viewGroup = (ViewGroup)findViewById(R.id.mylayout);
for (int i = 0; i < viewGroup.getChildCount(); i++) {
// do comparison to see if event.getX() and event.getY() fall in the view.getChildAt(i).getX(), getWidth(), getY() and getHeight()
}
}
精彩评论