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.
Related
I am trying to receive SMS from my android app. I have following receiver specified in my manifest.
<receiver android:exported="true" android:name="com.lahiruchandima.myapp.SMSReceiver">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
SMSReceiver successfully receives SMS if my app is installed and opened once (app does not need to be running at the moment the SMS is received to the device). But, if i do not open my app at least once after a fresh install, it doesn't receive any SMS.
Does anybody know a way to make it possible to receive SMS without opening the app at least once?
Does anybody know a way to make it possible to receive SMS without opening the app at least once?
It can't be done, on newer Android versions at least. Ever since Android 3.1, apps are installed in a stopped state, and require that the user open it at least once before components like your BroadcastReceiver can function. This is for security reasons, to prevent, or at least hamper, malicious program behavior.
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
I have an app that allows users to forward SMS messages as they are received. Back in the day, I had the android:priority in my intent-filter for android.provider.Telephony.SMS_RECEIVED set to barely above Android's default messaging app. I did so, so that the user can forward the messages without having to clear them in the messaging app. However, a few months later, Go SMS Pro released an update of their app with a android:priority value extremely high, so users with that app installed started having issues. I updated my app so that my priority was slightly higher than Go SMS Pro's and everything went fine. Now Go SMS Pro did it again, their android:priority has been taken up to the max value you can assign. 2147483647 on one of their broadcast receivers and 2147483640 on another (yes, Go SMS Pro has two broadcast receivers now).
To fix this, I tried changing my priority to max just like theirs, but somehow their app keeps wining the SMS fight even though our priorities are the same. I read somewhere that Android when having to decide between two apps with the same priority, it chooses the one installed the earliest. I tried installing Go SMS Pro AFTER my app, but still nothing.
What's the proper way to fix this? What are they doing in their app that makes them get the SMS broadcast before anyone else, even with same android:priority values?
What's the proper way to fix this?
Modify your app to survive being run after Go SMS Pro or any other app. You might also advise users if you detect apps monitoring the same broadcast with equal-or-higher priorities (use PackageManager for this), so they know to configure those apps accordingly.
Trying to have a higher priority than everyone else is an arms race, one in which you will eventually wind up, at best, tied with the same priority. The behavior of ordered broadcasts with tied priorities is undocumented, and therefore there is no guaranteed behavior. Android -- or customized versions of Android -- are welcome to modify the tie-breaker algorithm. That algorithm could be anything from:
alphabetical order by package name
order as found in a hashed collection, where the hash key could be based on anything (e.g., object ID)
random number generator
Since you cannot reliably "win", modify your app to be as successful as possible when you do indeed "lose".
go sms pro has set these lines in it's manifest for SmsReceiver:
<receiver android:name=".smspopup.SmsReceiver" android:permission="android.permission.BROADCAST_SMS">
<intent-filter android:priority="2147483647">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter android:priority="2147483647">
<action android:name="android.provider.Telephony.GSM_SMS_RECEIVED" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
<intent-filter>
<action android:name="android.provider.Telephony.WAP_PUSH_RECEIVED" />
<data android:mimeType="application/vnd.wap.mms-message" />
</intent-filter>
<intent-filter>
<action android:name="com.android.mms.transaction.MESSAGE_SENT" />
</intent-filter>
</receiver>
all these intent-filters make its priority higher than your receiver even if your reciever has the priority set to 2147483647. you can see the list of all receivers of all apps by:
List<ResolveInfo> receivers = getPackageManager().queryBroadcastReceivers(new Intent("android.provider.Telephony.SMS_RECEIVED"), 0);
the first receiver in the list, receives the sms before than others
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.
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.