I need to filter SMS in Android such that SMS which matches my condition moves to my application inbox and the rest go to native inbox.
But I can't delete/stop SMS reaching native inbox since abortBroadcast() is supported only for default messaging application. So, how can I handle this without making my application as default message application?
As far as I know google now assigns the largest possible integer for the default messaging app in the BroadcastReceiver's priority value. Therefore you can't catch the SMS before the default app to cancel it. (Thats what you have found)
The only method I see is to get the SMS in a lower level and delete it from the messages database using the from and to numbers and the timestamp.
Related
I'm trying to make a message application, which work along side the default messaging application. My application needs to intercept messages sent from a particular sender and not let default message application receive it. All other messages should be received by default message app.
After some searching I found that this is not possible from Kitkat onwards unless my message app is the default one. Therefore I thought of deleting messages from the particular number in default message app's inbox after receiving. But from kitkat onwards it is not possible unless my app made default.
Isn't there any way to do this?
What I want to do
Receive messages from a user specified number only to my
application while my application is not the default message application.
I am developing an Android App which receives SMS from a particular number constantly. I want my App to parse the SMS and display to the user accordingly. I wrote a broadcast receiver which intercepts sms and I can read the message sent from a particular number. However I do not want the user to get a push notification when the mobile receives an SMS from the number. Is there any way I can go about it?
From the android developer website, it seems from Android 4.4+ we cannot use abortBroadcast function to avoid broadcasting to the other applications.
Yes there is no way you can block the SMS going to other applications. But We have achieved this by customising the android framework which is proprietary implementation.
After checking the Android SMS API, I still get confuse about the document explanation.
http://developer.android.com/reference/android/telephony/SmsManager.html
In the API, it mentioned that SmsManager.sendTextMessage(), it described as below:
Note: Beginning with Android 4.4 (API level 19), if and only if an app is not selected as the default SMS app, the system automatically writes messages sent using this method to the SMS Provider (the default SMS app is always responsible for writing its sent messages to the SMS Provider). For information about how to behave as the default SMS app, see Telephony.
So, does it mean that only in Android 4.4 and above, if the app is not default SMS app, then using sendTextMessage() will also add to content://sms/sent?
If the device is below 4.4, then app is responsible for adding to content://sms/sent for the message sent?
I tested on sendTextMessage() on Android 4.3 and 4.2.2, it will not write to SMS provider.
http://developer.android.com/reference/android/provider/Telephony.html
In the Telephony API document about
Creating an SMS app
Only the default SMS app (selected by the user in system settings) is able to write to the SMS Provider (the tables defined within the Telephony class).
I don't understand what the tables defined within the Telephony class?
I tested in Android 4.4.2(Nexus 5), use sendTextMessage() then then add insert the sent message to content://sms/sent. It is successful. The app is not default SMS app. It still can access to the SMS provider. So i don't understand the document explanation that only default SMS app is able to write to the SMS provider....
For deleting a sms message
In the below thread:
Delete an sms from inbox
Here, replied that to delete an sms, need to delete on "content://sms/conversations/".
But why not from "content://sms/inbox"?
Thanks a lot for your kindly response.
Before KitKat was released I had developed an app which uses pre-defined short codes to perform transactions over SMS. For example, sending
"<PIN> BAL <phone number>"
would get you a reply with your credit balance. The user doesn't see the short codes, but instead picks the required function from a list, inserts his PIN and presses send. The message is formulated and sent by the app. The main point here is that his outgoing SMS (which contains his PIN) is not saved anywhere.
Since KitKat however, as long as my app is not the default SMS app, the outgoing SMS is saved in the default Messaging app. I can't ask users to set my app as default either, because it cant be used for normal messaging.
A solution or a workaround would be a lifesaver.
The main point here is that his outgoing SMS (which contains his PIN) is not saved anywhere. A solution or a workaround would be a lifesaver.
Forget it - there's no clean one. See docs:
Also, the system now allows only the default app to write message
data to the provider, although other apps can read at any time. Apps
that are not the user's default can still send messages — the system
handles writing those messages to the provider on behalf of the app,
so that users can see them in the default app.
What will happen when in an handset there are some apps which have defined some action on onReceive() method for any incoming SMS and any one app is calling abortBroadcast() method to remove sms from Inbox. Of course, I don't know that what priority they have defined in their App for their listener.
So in such scenario suppose I also want to perform some action on any incoming sms and also want to keep it in user's Inbox folder then how I will get that SMS when some other app have already read it and removed it too.
Since sms is a protected broadcast and only Android framework can send the broadcast, no one can do a abortBroadcast on it.
For storing of sms you should never use the Default sms contentProvider, since that will be updated by system Messaging application. You should use your own db or just fetch the items from the db already stored by default messaging application.