We have started to look into the Building Accessibility Service for Android at https://developer.android.com/guide/topics/ui/accessibility/services.html. Based on this documentation, we can perform custom gestures on behalf of user as mentioned under section "Taking actions for users" at https://developer.android.com/guide/topics/ui/accessibility/services.html#act-for-users.
We have following questions based on this documentation.
1) As we understand, there are gestures that user would perform and our code would listen to. Let's call these Listening Gestures. Then there are gestures that could be performed by our code for user. Let's call these Performing Gestures. Question is where do Performing Gestures impact - over touch-and-explore layer or underneath the touch-and-explore layer? For additional information, touch-and-explore is feature of Android Operating System that can be requested by Accessibility Services.
2) Does the Performing Gesture trigger any AccessibilityEvent which is notified to Accessibility Service? If yes, there's possible recursion if both Listening Gesture and Performing Gesture happen to be same. That is Listening Gesture could be swipe right which triggers some event. Performing Gesture is also let's say a swipe right. Now, this will also in turn trigger same event handler.
3) How do we determine that Performing Gesture executed successfully? The whole thing holds significance if Performing Gesture happens underneath the touch-and-explore layer.
Any help would be greatly appreciated.
1) No, performing gestures on behalf of users utilizing Accessibility service capabilities DOES NOT end up being caught as a "listening" gesture. The AccessibilityService actually sends the gesture through to the API that calculates screen touches in the exact same way that the screen does, circumventing the screen completely. So, these events are invisible to the assisstive technology. Though, if you hang on to a reference, you could of course call the callbacks from AccessibilityService for these gestures yourself. So, any gesture you perform will not trigger a touch to explore gesture. In fact, you could trigger performing a gesture as a result of a touch to explore gesture.
2) This, to me is actually the same question as question 1. No, it does not, because of all of the same reasons in question 1.
3) There are two answers to this. The first is 'dispatchGesture' returns a boolean. This boolean is true when the operating system runs into no technical issues dispatching your gesture. Potential issues for example would be: Your attempting to interact off screen. This would be stupid of you! LOL. If a "true" is returned from this method, your gesture was generally accpetable and was performed. At this point, we can be as sure that a gesture was performed as a user actually performing the gesture themselves. It's the exact same logic in the Operating System... check out the AOSP for yourself if you don't believe me :)
3B) The only way to be sure things are working is to watch your gesture take actions on the screen.
Related
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!
I know that it is easy to measure the touch pressure by using the function getPressure() provided by android API within an application activity.
However, I would like to measure all the motionevents (not only within the application activiy, but also outside the application activity).
How can I achieve this?
You can't, thankfully.
For security reasons, Android does not allow you to intercept touch events on anything outside of your own App's Activities. If this were allowed, a malicious app could take over and render the device useless by simply consuming all the touch events.
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!
Is it possible to detect touch events from within another application, specifically swipes? I'd like to be able to detect if the user has swiped left or right (even with 2 fingers - but not required). Perhaps there is a service or broadcast I can listen to.
or failing that, is there some API perhaps that I can poll say 10 times a second to get the touch state and I can compute the rest (why, I remember writing a mouse driver strobing the COM1 port with IN OUTs in 8086 assembler coded in a TSR on a XT...)!
Anyway, any help appreciated. (I think it could be done by hijacking the primary Launcher and having a transparent click-through on-top activity, but that's seriously fraud with danger!)
Is it possible to detect touch events from within another application, specifically swipes?
Fortunately, no.
or failing that, is there some API perhaps that I can poll say 10 times a second to get the touch state and I can compute the rest
Fortunately, no.
I think it could be done by hijacking the primary Launcher and having a transparent click-through on-top activity
Fortunately, no.
You are welcome to write your own home screen application, in which case you can track your own touch events on your own home screen. You are welcome to write an ordinary application and track your own touch events on your own activities.