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.
Related
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
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.
I have a floating view created in service, and I need to dispatch key events when I touch this view.
I have found out that view.dispatchKeyEvent() needs context of foreground activity, and key event dispatching only works when activity is foreground.
When you close/pause the activity and touch the view - nothing happens, even no NPE in LogCat.
Is there any way to use this method outside of main activity?
This may be a bit too little too late but I found a solution. (Assuming the OP still wants to trigger OS back button from a floating view or service.)
It seems like it is possible to tell Android to press the back button, if you're a registered Accessibility Service. (Once your component is registered with Android, user must explicitly enable it in System Settings. So if this is simply a niche feature for your app rather than a critical function, it may be an overkill.)
Once you're done registering .etc. accordingly, your background service may tell the Accessibility Service to perform the back button, which can be done by calling
performGlobalAction( GLOBAL_ACTION_BACK )
from the Accessibility Service.
You do need API Level 16 or above for this to work.
I haven't got around to test this, but according to docs, this should work.
Tried and works on a number of recent devices. (Kitkat, Marshmellow and Nouget)
I found the app Back Button (No root) on play store which seem to employ this technique to draw soft buttons for back, home .etc. (which works on LG Nexus 5X and Samsung Galaxy Tab A 2016)
HTH
If I right understand (you did not post any source you have), you need to have floating view over all over apps receives key events, outside your app.
There is some projects shows this ability. (forum-thread androidFloatingImage-repo)
Try to use this floating views example to create each other, or use exactly the same. I think, using something i wrote above you can use callback on key event correctly. Hope it helps;
Is there a way to subscribe to events from an installed app on a AVD? What I would like to do is, e.g., when I enter any text on a EditText field in the app, I want to automatically receive a notification in my program, with the details (entered value). Is there any way I can subscribe to the android app events from any installed apk ? If there are frameworks or any Android native drivers which can do this, please mention them.
It looks like you might be able to do something similar via Android's accessibility API. You'd need to write an Accessibility Service which would need to be installed and then explicitly enabled via the control panel (this is a security precaution to prevent arbitrary apps getting access to potentially sensitive contents of UI of other apps). Your service can listen to AccessibilityEvents - looks like TYPE_VIEW_TEXT_CHANGED event - "Represents the event of changing the text of an EditText" - is the one you want.
What you need is Google Analytics for Android
Im trying to develope an app which is an Overlay working on top of all aplications in the system, till there I dont have problems.
The issue is that my overlay has to be able to manage some events and others just let them go under it.
Example:
The App has to manage onFling events and do some operations.
The App must not manage onClick events, letting them go to the activity posicionated under its
I have found some information about how to do that, although you need to have root permissions to inject events in the system or another app running on it.
Here you can find further information :
http://www.pocketmagic.net/2012/04/injecting-events-programatically-on-android/#.UReb1KWIes0
http://www.pocketmagic.net/2013/01/programmatically-injecting-events-on-android-part-2/#.UReb3aWIes2