I'm working on an application that continuously logs to a file touch screen information (touch x,y coordinates), I'm using a MotionEvent event to access that information.
I want it to continue working even if the app is closed (home button is pressed).
After some research I found a Service component which can perform long-running operations in the background.
The problem is the MotionEvent is attached to a View and when the app is closed it is not triggering an event anymore.
Is there another way of accessing the screen sensors? or something else I can do?
I'd really appreciate any help I can get!
I want it to continue working even if the app is closed (home button is pressed)
That is not generally possible, for privacy and security reasons. Apps cannot spy on touch input destined for other apps.
You are welcome to explore implementing an accessibility service. Please bear in mind that those APIs are designed for helping people with motor control limitations use their device and its apps. As such, using those APIs for other reasons may not be supported by Google.
Related
I am working on an android app that should be used by students in some kind of practical test.
I am using the screen pinning that was introduced in Lollipop (startLockTask()), so when my app is launched the user needs to allow the locking.
I couldn't find a way to know when the user click ok for the locking and when he unlock the pinning? (The user can cancel the lock by holding both the Back and Recent buttons).
I am not looking for a way to know if the user currently in lock screen (getLockTaskModeState ()), i want to know if i have a way to handle the events of locking or unlocking.
I want that in the begining of the test i will be able to send information to my server if the users 'logged in' properly (by allowing the lock), and as well if the user unlock the device before the end of the test.
EDIT
Hey, people!
Please explain yourselves after downvoting!
If I wasn't exaplaining myself - i will try again if you will let me know.
I read a lot of questions and answers about general lock screen, but not the one of app pinning, I also read about check the status of the current task- if it is locked or not, but i didn't find answer to what i am asking - is there a way to handle the event of unlocking the 'screen pinning' of a specific app.
So please, explain your downvotes!
Device Admin Recevier class give you the event of pinning and unpinning... However the example use the class when the installed app is provisioned for device owner.. Not sure if you could use it. You may refer to this too : How to be notified when screen pinning is turned off in Android 5.0 Lollipop?
https://developer.android.com/reference/android/app/ActivityManager.html#getLockTaskModeState()
Just use the function as stated in the link.
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 have been trying to design an accessibility application for android for disabled people like that of ios7 switch control point mode. The biggest problem I am facing is how would I make an activity that would appear over all applications and takes switch events and send touch/tap events accordingly to any app over which it is running. I have searched and found that we could have a view that runs on top of other applications using system overlay mode but that does not let me send touch events. Please point me in right direction. Thanks.
You don't want an Activity. You want to develop and AccessibilityService.
http://developer.android.com/training/accessibility/service.html
Accessibility services receive callbacks from the accessibility apis, and are allowed to interact, draw views on top of, and send events to the applications that are running on the device. Once you register yourself as an accessibility service, you have much more power over the way the OS works, than you do within the confines of an application activity. You can even override touch events, and send your own! Though advanced gesture control is lost, as the gestures that you send are within the confines of the accessibility framework.
I am working on an application that monitors phone use (specifically, what time its being used). Presently, I log times of phone calls, SMSs, MMSs, Screen turning on, screen turning off, and keygaurd unlocking. Now I want to determine when the user does any interaction other than whats listed above. Like:
1) Application use (Detect when an application is launched by the user and/or when it is actively being used by the user)
For this I have been playing with the Activity Manager but there does not seem to be a good way to get the information I need. It has information about whats in the foreground, background and what services are running, but lacks information on the amount of use, time of use, time of application launch, ect.
2) General Screen Interaction (Detect when a user is interacting with the screen in any/all ways)
I have yet to find any way to detect any form of general screen or keyboard interaction while my activity is not in the foreground. Any help here would be appreciated.
3) Other (I am open to other 'events' that would represent a user interacting with their phone)
I am open to other ideas about what I could possible look for when detecting user activity.
Presently, I log times of phone calls, SMSs, MMSs, Screen turning on, screen turning off, and keygaurd unlocking.
Note that your SMS/MMS support is dependent upon an undocumented/unsupported API and may not work on all devices or in future versions of Android.
Detect when an application is launched
Fortunately, there are no broadcasts for this, to help limit the scope of spyware.
General Screen Interaction (Detect when a user is interacting with the screen in any/all ways)
Fortunately, there is no way to determine this, to help limit the scope of spyware.
Is there a way to register a receiver for a app running in the background for when a user presses a key. Kind of like "ACTION_USER_PRESENT" but if any keys were pressed on the screen.
MORE DETAIL: My app is running as a service in the background. User opens the phone and presses keys, like they searching for something online on their driod. Can I capture those key presses in the background?
To detect whether a user is using the device you could also use the information whether the screen is on or off as an approximation (making the assumption that the screen timeout is set). This blog entry shows how to capture the screen on and off events (I haven't done it myself though).
In the Android HCI Extractor ( http://code.google.com/p/android-hci-extractor/ ) we traverse the GUI and install some event filters (by using listeners) in the app top view.
Maybe if you can reach a top level view from which listen the events you could listen to all the events for this view. Let's try ;-)
This tool is an open-source prototype you can find here: http://code.google.com/p/android-hci-extractor/
It is very easy to integrate and use. In the tutorials you can see that only a few lines of code are needed: http://www.catedrasaes.org/trac/wiki/MIM
I hope it helps you!!