Detect all Android user events including UI "Clicks" & View Transitions - android

I am developing an Android Application and need to log my users "journey" through the application.
The events I wish to log include all user interaction events such as when the user clicks on a button etc, and also each Activity and/or Fragment visited.
I know I can litter my code with my logging logic however there are a number of downsides to this such as:-
using autoLink "web" and MovementMethod to allow the user to click on
a web url within a displayed TextView means I have nowhere to add my
logging code unless I use Spannables or a custom textView.
Developer human error will result in logging incorrect details or
missing logging altogether.
What I would like is a single point within the Android framework where I could intercept all UI events and Activity transitions.
I do not wish to create custom widgets to add my logging code.
Is it possible to place my logging code in one Android "hook" to allow me identify which widget was clicked in which Activity/Fragment?

Is it possible to place my logging code in one Android "hook" to allow me identify which widget was clicked in which Activity/Fragment?
No, sorry. Besides, that would be woefully insufficient:
There are many more UI events than just "clicks" (long-press, swipe, other single-touch and multi-touch gestures, key events)
Knowing a widget alone is insufficient, as your TextView scenario illustrates

Related

Android: click or scroll on behalf of user?

Is that possible?
I'm developing a service for disabled people. They can define voice commands and the service can detect the commands and execute them. Like when the user says "scroll down", The service (which is in fact a background process) takes control of screen and scrolls down (regardless of what application is on foreground), or touches a specific position and so forth. I wonder if this is possible in an android device? If not, what about a rooted device? (i.e the service has the root permissions). I know that getting voice input and processing it is possible. My question is about doing actions like touch (Action_Down) or scroll the user interface on behalf of a user.
Note that I don't have access to whatever application is running! In fact my service doesn't know about the application that is running on foreground. It might be a social media app or a messaging app or a game or whatever else! So in fact my service must be capable of defining input events like touch, swipe, scroll etc.
Thanks in advance!
Yes, that is possible.
For example, ListView has two methods for programmatic scroll:
listView.setSelection(id); //For instant scroll
listView.smoothScrollToPosition(id); // For smooth scroll
For an example of how to use voice triggered actions - check this answer out
For an example of how to inject events programmatically - check this link out

scroll android programmatically in all applications

I created a background service on android and I have two buttons which appear on the top of the screen all the time. I want to use these two buttons like scroll down and scroll up. But these two buttons should work on any kind of applications like Instagram, Facebook, Twitter and so. So, it means it should work in all applications that use scrolling.
I search a week on internet but I could not find any solutions.
This is not possible, sorry. Something like this would require your Service to have access to the Views of the applications and this would be a huge security breach, because you could read values from them and so on.
You could achieve this with a custom button code broadcast (so basically your buttons would act as physical buttons on the device) but this would most probably require you to have system-level permissions and some level of cooperation with the OEMs.
Android Activity class has a method called dispatchKeyEvent(), which could let you simulate the key input (with some limitations) but this is not present in the Service class.
Sadly this is not something you can do in Android. Typically you should not be able to touch views with a background service, the point of a background service is that you do some work in it (for example upload files to your web server or get some data). You CAN send a signal from a service once you're finished doing work to tell an app that something needs to happen, however the app needs to be specifically coded to respond to this broadcasted event.
If you wanted to do this with an app that you have developed, that can be achieved by using the onReceive method of say a BroadcastReceiver, however you cannot specifically define the behaviour of other apps as this would represent a security breach in Android.

Multi-window drag and drop in android N

Android N announced multi-window drag and drop feature, where we can drag and drop objects between activities.
This is the video of Google-IO'16 where they show the demo (9:56).
Do we have to do anything special to enable this feature in our app or we normally listen for Drop events (Assuming that I only want people to drop into my app from other apps ?
Can anyone give a link to the code sample for this ?
Do we have to do anything special to enable this feature in our app or we normally listen for Drop events
Assuming that you are using setOnDragListener(), your app will receive drop events regardless of origin (from within your app or from another app).
Note that you will want to call requestDragAndDropPermissions() in your ACTION_DROP handling, so that you have rights to any content referenced in the DragEvent. That is not necessary for in-app drop events, and it probably is not needed for simple text drop events between apps, but it becomes important for drag-and-drop of content represented by Uri values.
Can anyone give a link to the code sample for this ?
This project has a pair of app modules. drag/ implements an activity that allows you to drag a photo from an ImageView via a long-click gesture. drop/ implements an activity that accepts the dragged image. The image is shared via a FileProvider.

Is there native touch listener in android?

In java i can listen to native clicks using NativeMouseListener from the global screen,
Is there any way to listen to native touches in android?
means listen to touch from the other global activities
Moving this in as an answer, as it has been confirmed by #adelphus in comments:
It's my understanding that unless you KNOW the package name, and have access to it, you cannot intercept anything that goes on in it. Including where the user touches the screen.

Android service to monitor click events

I've just started getting into Android development and as a proof of concept I am tasked with creating a click logging system for several applications. These applications may be written by other teams within my organization or may very well be any application downloaded from Google Play.
So is it possible to create a service that monitors every click event from any application running? Any type of global onClick Listener?
If so, any pointers in the right direction would be helpful, thanks.
You can try adding a transparent view to the global window manager, same place toast messages are added. Then you can just intercept touch events via by overriding the onInterceptTouchEvent() method on any viewGroup and passing the event down.
Many apps have a similar approach (AnyDo is one of the apps that add a view in this manner, Facebook Home as well).
So is it possible to create a service that monitors every click event from any application running? Any type of global onClick Listener?
Fortunately, not on Android 4.0+, for obvious privacy and security reasons. Such a "tapjacking" attack was possible on earlier versions of Android.

Categories

Resources