I was troubleshooting a view-related issue: a click listener that is not fired when it's supposed to. After a long session of trial-and-error, I found out that a parent view was disabled, thus discarding all events to its children.
Is there a way, in Android, to find exactly what happens to a touch or click event when it is injected to the app? Like how was it dispatched, which views were traversed by it, who ignored it (and why), who discarded it (and why) and finally who consumed it.
Ideally it would be some kind of low-level dump on Logcat emitted for every click in the app.
As you can see in the similar post at the issue tracker Dianne Hackborn writes:
There currently isn't a way to do this.
Meaning, there is no such an API in the framework.
But you can have a custom root ViewGroup and listen for each and every touch event (via onInterceptTouchEvent()) and dump the MotionEvent.
I believe that's the only possible way so far.
Related
I am keen to know how Android's event handling and dispatching work. Code walk-through is an option, of course. But, if there's any document one can refer me to, that'd be great.
As a concrete example, consider a click event on a button. How does that click propagate within the framework? In case of multiple event occurring one after another, is there some sort of event queue, and a dispatcher calling methods on the events in the queue? What goes on under the hood? If not any document, if one can point me to the relevant part of the code I should look at, that'd be great.
According to my knowledge the parent is the first asked, if he can handle the event, otherwise he asks his childs who can handle this event ?
https://developer.android.com/training/gestures/viewgroup
I want to know if it is possible to generate automatic touch at regular intervals of time, say 5 seconds in another application.
For example..I want to develop an application which will create a touch response just as we touch the screen, at a particular coordinate at regular fixed interval.
Please help.
It's possible to create and dispatch touch events in your application. It's pretty easy. Look at View.dispatchTouchEvent method and parameters. You have to override that method in root view group so you can pass your events to all views in the activity.
It's not possible to access other applications though (due to security reasons).
edit: seems like dispatchTouchEvent is public, so no need to override
I am an undergraduate research assistant working on an android accessibility project. My task involves collecting as much data about the user experience as possible, including touch events and other view interactions. I require 2 services: an accessibility service to gather details about the view current interaction, and a TouchListener service that is able to intercept MotionEvents.
My problem is with the TouchListener service. Is there any known way to intercept all touch events and pass them on to the current view?
Essentially, it seems like an invisible system-overlay view is needed to constantly listen for touch events, but the view can either intercept all touch events and NOT pass them to the view behind, or it can pass the even back and register the touch event as an ambiguous ACTION_OUTSIDE event, giving no details about the interaction.
My question is similar to this one, and the obstacle is discussed here. If anyone has found a work-around, please post!
When registering to mousedown and touchdown events on a webview both are triggered at the very same time, leading up to the odd situation of having twice "mousedown-like" events to deal with. There's a known workaround which consists of calling event.preventDefault()... but I cannot call it because I do need to get the default behavior anyway. And of course I cannot remove the regular mouse events listeners neither without no longer being compatible with a regular computer.
There's another known workaround (found here: http://www.quirksmode.org/blog/archives/2010/02/do_we_need_touc.html) which consists of detecting whether the first event that we receive is of touchevent type or not, in the former case we then simply remove the listeners to the mouse events.... But I've found it ugly and moreover I can't believe why the Android's native browser keeps firing mouse event whereas touch events are registered and there's no way to prevent that from happening in the manifest or somewhere else.
Btw: this issue doesn't occur on Safari mobile.
Thank you very much!
I need to make a service that capture all touch events, not in a specific view or when an specific activity is open. This service is started when the boot is completed (and I have an app to stop/play this service when I want it). So it write something (in a Toast) when the user touch any place in the screen.
Can I do this? Or only in specifics things (with OnTouchListener and adding specifics views, for example)?
Sorry for my bad english.
thanks
If you override the View itself and build your own ROM, you will be able to have these kind of things. So, straight answer will be just no. Sorry.