silently consuming an SMS on android? - android

I wonder how would one 'consume' certain SMS messages that are received by an android device, based on custom criteria (content or sender, etc.). for this, I registered a subclass of BroadcastReceiver, which is fine, as it does get the SMS message. but the message is sent to the 'standard' SMS store as well.
would anyone know if it is possible to 'consume' the message? that is, remove it from the queue, and make sure that the 'standard' SMS handler does not receive it?

thanks for all the pointers.
the answer to the question is that one has to use abortBroadcast() in a BroadcastReceiver, but most importantly one has to turn the message queue into a priority queue, otherwise abortBroadcast() doesn't work. fortunately it is possible to do this in the manifest:
<intent-filter android:priority="1">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
note the android:priority="1" attribute in the intent-filter element.

Related

android:priority value for broadcast receiver to get sms first in my app

i want to receive sms in my app, but if there is any other app is receiving sms as well , sms will go to that app and i cant do anything with it .
i want to receive sms first in my app
enter code here<receiver android:name="pk.wisesolutions.smsmanager.activity.IncomingMessage" >
<intent-filter android:priority="999" >
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
SMS functionality has changed as of KitKat (version 4.4, API Level 19).
i want to receive sms in my app
This is still possible, if your app has the RECEIVE_SMS permission, and has an appropriately configured BroadcastReceiver.
if there is any other app is receiving sms as well , sms will go to that app and i cant do anything with it .
The concept of a default SMS app was introduced with KitKat. The app chosen as the default SMS app listens for the SMS_DELIVER action broadcast, and is responsible for handling the appropriate notifications and Provider writes. Only the default app has control over messages being written to the Provider.
The SMS_RECEIVED action is still broadcast, but it cannot be aborted. This means that your app can still listen for and retrieve incoming SMS messages, but it cannot stop other apps from doing so as well, and vice versa. Though the maximum practical priority you can set for your Receiver is 999, it is rather irrelevant, in this case, because abortBroadcast() will not work, and any app listening for the SMS_RECEIVED broadcast will still get it. If your app is not receiving and handling this broadcast, there are other things going on.

android.provider.Telephony.SMS_RECEIVED won't fire when SMS comes from an e-mail

My BroadcastReceiver works just fine when the device receives an SMS from another regular phone, but if the SMS is sent through the carrier's e-mail gateway like "myphonenumber#mycarrier.com", then the message is received on the device normally as an SMS, but the android.provider.Telephony.SMS_RECEIVED action does not fire and my BroadcatReceiver never gets notified. Is there something I'm missing?
<receiver android:name=".services.IncomingSmsBroadcastReceiver" >
<intent-filter android:priority="2147483647" >
<action android:name="android.provider.Telephony.SMS_RECEIVED" >
</action>
</intent-filter>
</receiver>
I found something interesting about how carriers handle e-mails, which in turn was causing wrong behavior in my if statements, which in turn caused the problem stated in this question.
Apparently, when cell phone service providers handle e-mails to your phone, they send it through a random short number: like 4043 for example. In your BroadcastReceiver, when you get a hold of the SmsMessage, you should always use SmsMessage.getDisplayOriginatingAddress() and SmsMessage.getDisplayMessageBody(). These will give you the e-mail address that sent it and the proper body respectively. Unlike SmsMessage.getOriginatingAddress() and SmsMessage.getMessageBody() which will give you instead the random number mentioned previously and the body containing the e-mail address mixed up with the actual content.

Android: SMS is blocked by ChatON app

I have written an app which receives incoming SMSes, saves it and displays it to the users. Suddenly my app stopped receiving SMS due to Samsung's ChatOn app update.
Here is the my Manifest.xml:
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<receiver android:name="com.myapp.sms.service.SMSReceiver"
android:permission="android.permission.BROADCAST_SMS" android:exported="true">
<intent-filter android:priority="999">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
I had this issue earlier with Hangout which started supporting SMS. So, at that time I added priority to 999 (max value) in manifest file. And this worked.
But after recent update of ChatOn app, my app stopped receiving SMS. Please tell me how can I overcome with this.
For work around, I unchecked SMS option on ChatOn app.
Any help is appreciated.
There is no guaranteed way that your app can get "first crack" at SMS messages, on Android 4.3 and below. Even if you set your app to be the highest possible priority, other apps can do the same. GoSMS notably does this, and you have indicated that ChatOn does as well. If they get the message first and abort the broadcast, you will not receive the message.
There is nothing that you can do, other than to detect this possibility (using PackageManager) and alert users as to the potential behavior.
Note that on Android 4.4, this is a lot different:
The broadcast can no longer be aborted
There are separate broadcasts for apps that are monitoring SMS and the actual final SMS client app

Android abortBroadcast() works strange

I make some program, which removes unwanted SMS from phone (by special filter).
It uses aborBroadcast() meted to stop SMS.
In emulator, it works okay, on some mobile phones (I tested with Android 2.2) too.
But in some phones (Samsung, 2.3.3) it does not stop SMS. And after my program removed, mobile receives ALL sms again, which was aborted.
My android.manifest code:
<receiver android:name=".SmsHandler" >
<intent-filter android:priority="2147483647" >
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
My handler code:
if msgText.contains(GlobalVars.getInstance().getFilterText())) {
abortBroadcast();
}
Maybe, somebody can advice me?
There are two types of broadcasts, ordered and unordered. As far as I know, SMS is an unordered broadcast, and that is why you can't really abort it.
http://developer.android.com/reference/android/content/BroadcastReceiver.html#Security
I am not sure when you say that it works on some devices. Ideally, it shouldn't for the SMS received broadcast.

Change Android's default programs?

If i'm developing an alternative Android SMS application, is there any way to replace the default sms application with my, so that my app receives the incoming sms message?
you just have to set a higher priority for your broadcast receiver like this. For example 100
<intent-filter android:priority="100">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
Then you have to call abortBroadcast(); when you want it to stop if you dont want it to propagate. This only works for orderedbroadcasts.
You cannot enforce your app on the users. As Corey mentioned users will have to switch off sms notifications in the default app to not getting the notification twice.

Categories

Resources