Get software key presses in a service - android

I'm trying to develop an app that, according to some pattern pressed on the keyboard (like swipe, but not that complex), it will do some action. For example, if the user presses two keys at once, it will do some action. This has to be a service, because my won't have a gui. It will just do the actions. I read that it's not possible, as it would create a security hole, so I'm open to suggestions on how I can tackle this problem. I've thought of this way:
1. Create an accessibility service and get the key events (easy for hard keyboard, but I don't know about the soft keyboard.)
Could you give me any other ideas, or help me on how to get soft key events in an accessibility service?
Thanks!

Related

trigger every key press in android in background

i am developing android service and I want to know is there anyway that can let me know what is the user typing every key clicked whatever keyboard he is using
for example if the user clicked the letter 'k' from samsung keyboard, i want my service to know that, I could manage this if the user used my custom keyboard, but I want to know even if he is using his default keyboard. and thank you.
I want to know is there anyway that can let me know what is the user typing every key clicked whatever keyboard he is using
NO, there is no way and it's completely illegal.
However Android let you the opportunity the create a custom keyboard using InputMethodService. Once you have created soft custom keyboard and the user have enabled it then you can track every key of user with the callback method onKey()
Also, let me remind you that this is only for the good intentions like word-suggestions and predictions

Android . Activating my application when some string was entered in some other application

I am trying to create a behavior where entering some string in any application will open my application.
I've tried looking around on how to listen for keyboard press or listening for text change, but I couldn't find my required behavior and I don't want to create a custom keyboard for this.
If this is not possible, what will be a good implementation for lunching my application as fast as possible while in the other application?
Answered before the requirement to "don't want custom keyboard"
The only viable way that I can think of is if the user was using a custom keyboard written by you. Custom keyboards can and do act as key-loggers and therefor could detect any key combination, or written word and allow you to execute your code when your conditions are met.
Rerfer to Creating an input method docs
How to open my app as fast as possible from another application?
Press home, launch your app by clicking on the launcher icon
But assuming you mean without doing that, you'll still need to monitor some event, say volume keys pressed or device being shaken for instance, or have you app be running already in the foreground such as what Facebook messenger does (or used to do, I don't know)
Related questions:
What APIs in Android is Facebook using to create Chat Heads?
Listen to volume buttons in background service?
How to detect shake event with android?
Demo of bubbles

android replace unlock screen

I am searching for a way to implement a custom unlocking screen for Android. There seem to be lots of questions about that but no real way to do that, am I right?
Solutions I found are about creating an activity that is invoked by some mechanism, that have to disable or bypass the home key and other keys and so on.
The simplest way in my imagination should be giving android an activity and say hey if you lock the screen and the user wants to wake it up, call this and wait for it to respond if unlocking is ok or not.
Handling stays within the system, that activity does not have to receive any key events, the system does not respond to home key in this situation...
Is there a chance?

Android detect general keyboard events made by other apps?

Is there a way to detect some general keyboard events made by other apps? I understand that the specific keyboard events(e.g. key "b" pressed) should not be exposed due to security reason. But are general events like keyboard show/hide broadcast in any way? I did some search but did not find it available.
Keyboard show/hide is not an event you can listen for, not even in your own app (there are some hacky workarounds within your app, but it seems like you want to do this externally). I don't believe keyboard events are broadcast in any way. They may be delivered to the current Activity window in focus (and to its Views), but I have seen nothing to suggest that they are broadcast across the system.

Android user presses a key

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!!

Categories

Resources