I'm writing application which handles SMS's and as I plan it should replace stock/default application.
I'm intercepting android.provider.Telephony.SMS_RECEIVED broadcast fired by incoming SMS and publishing my own notification and then calling abortBroadcast(), so in the end there is no notification for incoming new messages which leads to default/stock app.
But the problem is in fact that when user doesn't read for a long enough time (smth like several minutes) incoming SMS stock/default app aroses another broadcast - I suspect just checking that there's unread sms. So user sees 2 notifications: one from default/stock messaging app and another one from mines, which is messing.
I can't find which broadcast fired when there's unread sms?
Any ideas, hints?
You can set the priority of your receiver this way, so you know that it has the top priority and will execute the onReceive() method:
<receiver android:name=".SmsReceiver" android:enabled="true"
android:exported="true" android:priority="999">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
Related
i want to make an application in which i start service which start broadcast reciever for sms_read and every time when new sms come and reciever detact that message. no matter app is running or not.
you don't have to use a Service for Reading and listening for SMS.
All you need to Do is just register a Broadcast receiver in your Application like this .
<receiver android:name=".IncomingSms" >
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
And just write whatever functionality you have to do upon receiving the SMS in the Broadcast receiver by starting an IntentService or a Thread
Before Android 4.4 I was able to stop messages from moving to inbox by setting the priority like this
<receiver android:name="com.serviceschedular.helperClasses.SmsReceiver" >
<intent-filter android:priority="1000">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
and then abortBroadcast() in onRecieve() messages. However in Android 4.4 we need to define SMS_DELIVER_ACTION in order to make our messaging app as default :
Getting Your SMS Apps Ready for KitKat
By doing this I can receive messages first and they don't move to any other messaging app but I also need to send them to messaging app if it doesn't fill my criteria. So is there any way around to achieve this functionality?
This question already has answers here:
SMS Broadcastreceiver not called when GO SMS Pro installed
(2 answers)
Closed 9 years ago.
I have implemented an SMS receiver which intercepts incoming SMS messages without any issues. However, when I install GO SMS Pro and set "Disable other message notification", then my app does not receive any broadcast message even though I have set the priority on intent filter very high. Is there a way to overcome so that my app always receive a SMS broadcast irrespective of what user does on Go SMS Pro's app, especially since my app does not show any UI pop-up notification? As soon as I uninstall GO SMS Pro, my app starts getting incoming SMS broadcasts and works fine.
Here is the log when an incoming SMS is received and GO SMS Pro is installed. There is some magic done by GO SMS Pro which I don't understand. Can someone explain what is done here and how can I make sure my app does get ordered broadcast notification every time.
add following code in your manifest in broadcast receiver declaration
<receiver
android:name="com.application.reciever.SMSReceiver"
class="com.application.reciever.SMSReceiver" android:exported="true">
<intent-filter android:priority="999" >
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
"The value must be an integer, such as "100". Higher numbers have a higher priority."
Hope it will help you.
GO SMS have set their on absolute maximum of 2147483647 (2^31-1). So if you set it same priority then in that case Android OS will pass broadcast to older app i.e (first installed app) would get the notification.If Go SMS Pro is installed prior to your app you should warn your users about the situation. They could configure Go SMS Pro differently or uninstall it and then re install it again so your app can work too.
<receiver android:name=".SMSReceiver" >
<intent-filter android:priority="2147483647">
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>
Then in SMSReceiver onReceive() you need to add abortBroadcast() to abort any further Broadcasts
public void onReceive(Context context, Intent intent) {
abortBroadcast();
}
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.