Intercept intent to open text messaging? - android

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.

Related

Is it possible that one android app sends clicks to another open android app?

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.

Detect when app is opened with a service

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.

Is it possible to fake an incoming SMS on Android?

In a certain situation, I'd like my app to be able to "fake" an incoming SMS on the user's device, as a sort of notification. This would save me money when I'd normally use Twilio to send a text to my users but I know they already have my app. Is there any way to do this? I imagine it would have something to do with Intents and Content Providers but I don't really know where to start.
To clarify:
I'm not new to Android and I do respect all of the normal Notification methods. However, my app will have an opt-in for text messages and I'd like to be able to trigger them for free rather than paying for it. This is for SMS-specific uses and not as a substitute for a normal Notification.
Yes (although I really don't support doing this) it is, in theory possible by creating and broadcasting the proper intent. Specifically, they android.provider.Telephony.SMS_RECEIVED intent will be received by anybody who is listening for SMS messages, including the default SMS application. This will in turn cause the notification to be displayed.
All of that said, I've only ever done this in a custom version of Android from within the system process. I'm really not sure if a generic application can do this (in fact, I kinda doubt it). The other caveat is that you will need to formulate your data into PDU's which represent the binary data format of an SMS message. You can look this up, but it's nontrivial.
A far better approach would be to simply have your application display a notification in the tray, the way well behaved applications are supposed to notify the users of events. Take a look at the Notification class.
If you install the apk named ApiDemos-debug.apk that usually comes installed with your choosen platform for the SDK, you will find an example in
<Api Demos> > App > Notification > IncomingMessage
the complete source for this package is usually under
<SDK root>/samples/android-xx/ApiDemos

Knowing when the Clear button is pressed

Is it possible (i'm sure it is because i've seen other apps do it) to know when the clear notifications button is pressed without having an active notification?
For instance, I need to know if the user has an SMS notification, if he pushes clear I would like to be told. Is there a callback for this?
Is it possible (i'm sure it is because i've seen other apps do it) to know when the clear notifications button is pressed without having an active notification?
No, it is not possible.
I need to know if the user has an SMS notification
No, you do not. For starters, there are a few hundred SMS clients, many of which will use Notifications, so there is no singular "SMS notification". And, as noted, you do not have any means of determining when other applications add or remove Notifications.

Global control handler

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.

Categories

Resources