I have an Android service that runs in background.
I need it to recieve feedback (and stop, for example) just when user did something, no matter if it's only touch event on homescreen of somewhere else or key press.
Is it possible to handle global touch and key events?
While I highly doubt that there is an easy way to do this, you can register intents and intercept the messages for your own purpose. Have a look at the intent library for specific intents that you might hijack for your application. You may find further information in the android documentation on intent filters.
Related
I´d like to control an app with another app.
As far as I know apps in background get paused.
Is there any way to send commands/clicks etc to another app by my control app?
Thanks
Not generally. If you wrote both apps, you are welcome to implement your own control IPC mechanism. An accessibility service can do what you want to a limited extent for arbitrary apps, but nobody with any sense will install your accessibility service, given that you can do all sorts of nasty things to the user and so there are security warnings that get raised when the user goes to activate your accessibility service. On rooted devices, there are probably many more options.
If you want to send click events to another App, you can achieve it by Broadcast Receiver.
You have to send a broadcast message and the other app must have a receiver to receive the trigger.
you can get more information about broadcast receiver by this link https://developer.android.com/guide/components/broadcasts.html
What you are looking for is a service. In a bounded service, Inter process communication is extremely easy, read here.
https://developer.android.com/guide/components/bound-services.html
You simply bound both your apps to a service they can talk to eachother.
I have an application I want to be an alternative handler for outgoing calls.
It would make sense to have an IntentFilter to handle CALL or CALL_PRIVILEGED intents. But that's actually not the right way to do this as doing so can interfere with EMS/911 calls. According to Google, you should write a BroadcastReceiver that looks for a NEW_OUTGOING_CALL. See following link:
http://android-developers.blogspot.com/2013/05/handling-phone-call-requests-right-way.html
So I've done this, but I want the behavior to be the same as if their were multiple activities with IntentFilters to handle the processing for the outbound call, i.e., I want a Chooser to come up for the User to decide which App he wants to handle the Intent.
Writing this the "wrong" way, I get this functionality for free. How do I get it by going via the BroadcastReceiver route?
I want to be able to detect when an application is opened and notify the user of something at the moment related to that same application but I don't know how to do this.
The user opens my app
I intent the service (background / foreground) and it successfully starts
Whenever the user opens another application I want to "catch it" and present a notification to the user
How can this be made? Are there any event listeners i need to use? Thank you very much.
If you are trying to catch "open app" intents in general, then it depends on how the app defined the intent. If it specified a class (explicit intent) then it will generally not be visible to your app unless the device is rooted, for example.
Implicit intents are broadcast and you simply need to define an intent filter in order to receive them. These are intents that allow Android and/or the user to select the appropriate app target based on data sent with the intent.
There are both useful and malicious motivations to do the kind of thing you are asking about. Read this:
Android Intent Security
And also the posted comment on learning about intents overall.
This is really simple. Here I am trying to figure out the solution. When your app goes on onPause() state then broadcast a message using BroadcastReceiver. On the other hand in another app just register for that broadcast.
Suppose a user opens up the default messaging application, scrolls through their text message inbox, and then clicks on a specific person to open up the text messages between them. Is it possible to intercept and act upon the intent fired when they click on that person's name?
To clarify, I don't want to stop other applications from receiving the intent. I suppose intercept was a misleading word. I just want to know if there is some way to detect that the text messaging screen is being opened as well as who it is to.
I strongly believe no. Such capability would pose quite a security risk as "developers" with mischievous intentions could secretly have their app intercepting intents all throughout the device. I would suspect you have to create your own messaging app to accommodate what you have in mind.
I think you're putting to much significance on Intents. That is actually just an action internal to the application. Not everything you click in Android results in an Intent being fired and even if it does, not all intents are broadcast to everybody. In this case, what happens is you touch a list and it opens up another activity, likely via startActivity (which does make use of an Intent but not a broadcast). Additionally, it's not possible to "intercept" Intents. You can act on them, sure, but you can't prevent other applications from seeing them if they are broadcast.
I have a program that has a broadcast receiver that listens for Phone_State and then sends a user defined intent.
Well, my problem is that the system also sends out an intent (the one that I am trying to replace with my program) .
So I am trying to find a way to CANCEL the systems intent.
I have found that if i have a timer just wait for a little bit, then I can send mine after the systems, but that is not very good, and sometimes defeats the purpose of my program.
Also, i cannot set my program as a default because it is not a full dialer program. Just one action of it.
Someone please help me find how to listen for and cancel a system intent/activity....
Someone please help me find how to
listen for and cancel a system
intent/activity
You cannot "cancel" an activity, period.
You cannot replace the dialer.
If the system Intent was sent via sendOrderedBroadcast(), then you can call abortBroadcast() from your BroadcastReceiver, and any lower-priority receivers will not get the broadcast. However, I have no evidence that ACTION_PHONE_STATE_CHANGED is an ordered broadcast, and I sincerely hope it isn't.
Whatever you are trying to do probably should be accomplished via modifications to your own custom firmware.