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.
Related
I have gone through many documentation but haven't clarified yet on the list of rules a default sms should follow!
Android-Dev-Blogspot says this:
only the app that receives the SMS_DELIVER_ACTION broadcast (the
user-specified default SMS app) is able to write to the SMS Provider
If our app is default sms App should we manually write all the incoming and sent sms to the db or does the system handles that.
Its not properly explained anywhere or maybe I am missing it. I need to know all the rules of being a default sms app. Any help would be appreciated!
The default messaging app is responsible for writing all incoming SMS messages, and its own outgoing messages. SMS messages sent by non-default apps will be written to the Provider automatically by the system.
The official word on this is spread across two documents. The 4.4 API release notes state:
Once selected, only the default SMS app is able to write to the SMS Provider and only the default SMS app receives the SMS_DELIVER_ACTION broadcast when the user receives an SMS... The default SMS app is responsible for writing details to the SMS Provider when it receives or sends a new message.
That blog page, which the release notes also link to, covers the non-default situation:
If and only if an app is not selected as the default SMS app on Android 4.4, the system automatically writes the sent SMS messages to the SMS Provider (the default SMS app is always responsible for writing its sent messages to the SMS Provider).
Question regarding content://sms/inbox:
1) Is it advisable to explicitly store incoming messages to inbox?
2) What if an android device has a native messaging app and my messaging app was installed to it, and then I explicitly store incoming messages to inbox, will the messages duplicate?
3) Does android automatically store new messages to inbox regardless if there is a messaging application?
Thanks.
Regarding SMS, details vary depending on the Android version. Prior to KitKat, the SMS API was undocumented. With KitKat, the concept of a default SMS app
was introduced, and the SMS API became public.
Is it advisable to explicitly store incoming messages to inbox?
Pre-KitKat: Yes. If your app is the main or only SMS installed, and no other app gets the SMS_RECEIVED broadcast.
KitKat and on: If your app is the default SMS app, then it is responsible for writing the incoming messages to the Provider. If it isn't the default, then it's irrelevant, since your app won't have write access to the Provider.
What if an android device has a native messaging app and my messaging app was installed to it, and then I explicitly store incoming messages to inbox, will the messages duplicate?
Pre-KitKat: Yes. Unless your app intercepts and aborts the SMS_RECEIVED broadcast, the native app will write the messages.
KitKat and on: Only one app can be the default at any given time, and only it has write access to the Provider. When an app is not selected as the default, it is expected to adjust its behavior accordingly.
Does android automatically store new messages to inbox regardless if there is a messaging application?
Pre-KitKat: No. Native messaging apps are configured to handle the writes. The system doesn't do it automatically.
KitKat and on: No. As mentioned, the default app is responsible for writing incoming messages to the Provider.
My Android app uses SMS to silently send out notifications. Prior to Kitkat these notifications were not recorded into the SMS Provider and hence did not appear in the user's conversation lists. This is the app's desired behavior.
With the Kitkat SMS changes (refer SmsManger documentation quoted below) these messages are still being sent but are now automatically being written to the SMS provider and thus appearing in the user's conversation lists. This is undesirable for my app.
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.
It sounds like I could prevent the automatic writing to the provider by making my app the default and then not writing to the provider. However, this would be a terrible user experience in the context of my app, so I would only consider it as an absolute last resort.
My question is then - is there a way to silently send SMS in Kitkat without my app having to be the default app?
I've read the responses to this question Send SMS message using non default SMS app on Android 4.4 but that is more concerned with ensuring that the messages are being written to the provider. I don't want that.
Short answer is no.
Long answer :
There are actually options but it involves a lot of work. One is to download the source code for aosp and modify the mms.apk to allow it to receive intents from your app to send sms without writing to provider.
Another way is to baksmali your phones default sms application and add smali code that would allow you to do the same as above. This would require technical knowledge of smali and decompiling/recompiling apks.
With that said, there are problems that will arise such as what if the phone user decides to use a third party sms/mms application for their short messaging needs.
I have an app that has device admin rights. My app monitors received SMS's and passes the content through some logic. Can i change the default SMS app to my app programatically . My app checks for spam messages so it needs to read/write/update SMS db. I want a fix for kitkat.
I just noticed that the incoming SMS notification on my app are no longer notifications for new SMS that are received , but instead are "new Hangout message" notifications that are caused by hangouts receiving the incoming SMS. So my app is also not able to receive incoming text messages with SMS_RECEIVED.
Google's Android Developers Blog post about the new SMS API in Kitkat, said that nothing would change for apps using just SMS_RECEIVED and don't try to write the SMS to the SMS Provider.
1 I always believed that the SMS_RECEIVED broadcast is abortable. But the Android 4.4 APIs site says something different: "…when a new SMS arrives by listening for the SMS_RECEIVED_ACTION broadcast, which is a non-abortable broadcast…"
Can i change the default SMS app to my app programatically
Not directly. You can prompt the user to change the default SMS app.
My app checks for spam messages
Repackage your code as a library and license it to SMS clients.
So the Pebble app is also not able to receive incoming text messages with SMS_RECEIVED
Possibly the Pebble app is simply having other problems and is crashing before it notifies the Pebble. Or, possibly the Pebble app is updated for Android 4.4 and, since it knows it cannot stop the Hangouts notification, simply suppresses its own.
Google's Android Developers Blog post about the new SMS API in Kitkat,said that nothing would change for apps using just SMS_RECEIVED and don't try to write the SMS to the SMS Provider
That is not what this blog post says.
I always believed that the SMS_RECEIVED broadcast is abortable
This undocumented, unsupported broadcast had been an ordered, abortable broadcast through Android 4.3. That is no longer the case with Android 4.4, as you can tell by reading the aforementioned blog post:
Note that—beginning with Android 4.4—any attempt by your app to abort the SMS_RECEIVED_ACTION broadcast will be ignored so all apps interested have the chance to receive it.
I'm currently developing an application that needs to deal with SMS only if it is an SMS expected by the application (same behaviour as Whatsapp on registration).
I would like to abort the SMS Intent as it is not expected to appear in the SMS box.
My question is : I know that Google changed a lot about SMS behaviour in KitKat, and now, even if my SMS is well parsed by my application, the SMS also appear in SMSBox, even if I call this.abortBroadcast(); in my SMS broadcast receiver. So is there a way to avoid those SMS appearing in SMS box without having to develop a complete SMS application ?
For information, the priority is yet to 1000 (and I tried also with MAX Integer) in Manifest file for this Broadcast Receiver.
Hangouts uses the maximum possible priority (999 per the Intent-Filter docs) and therefore you cannot abort it on <4.4 releases. On 4.4+, only the default SMS app (blog post with details) can make changes to the SMS Provider (i.e., automatically delete the SMS).
You can't stop a message from showing in Default SMS application in kitkat. Checkout following links for details:
https://code.google.com/p/android/issues/detail?id=61684
http://android-developers.blogspot.co.uk/2013/10/getting-your-sms-apps-ready-for-kitkat.html
You can block SMS on Android 4.4 - 4.4.4 using
1)
Using AppsOpps setting
WRITE_SMS permission
Sms will be deleted in 10 seconds with notification about this sms.
As option you can block sound on receiving unwanted sms.
2) Set up your app as default sms app.