How to Save Sms to Inbox in Android

android -how to save sent messages sent via SmsMessage

Sms content provider can help you to write data into message inbox:

    ContentValues values = new ContentValues();
values.put("address", tel);
values.put("body", text);
values.put("date", "135123000000");
getContentResolver().insert(Uri.parse("content://sms/sent"), values);

Permission required:

 <uses-permission android:name="android.permission.WRITE_SMS"/>
<uses-permission android:name="android.permission.READ_SMS"/>

How can I send SMS without save in inbox or sent folders - Android

Is your app running in android 4.4 and above?

Starting from Android 4.4, you cannot send the sms without showing in the sentbox.

Outlined at https://developer.android.com/about/versions/android-4.4.html#SMS you can see the changes.

SMS Provider The Telephony content provider (the "SMS Provider") allows apps to read and write SMS and MMS messages on the device. It includes tables for SMS and MMS messages received, drafted, sent, pending, and more.

Beginning with Android 4.4, the system settings allow users to select a "default SMS app." 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 or the WAP_PUSH_DELIVER_ACTION broadcast when the user receives an MMS. The default SMS app is responsible for writing details to the SMS Provider when it receives or sends a new message.

Other apps that are not selected as the default SMS app can only read the SMS Provider, but may also be notified when a new SMS arrives by listening for the SMS_RECEIVED_ACTION broadcast, which is a non-abortable broadcast that may be delivered to multiple apps. This broadcast is intended for apps that---while not selected as the default SMS app---need to read special incoming messages such as to perform phone number verification.

For more information, read the blog post, Getting Your SMS Apps Ready for KitKat.http://android-developers.blogspot.my/2013/10/getting-your-sms-apps-ready-for-kitkat.html

Do I need to manually insert new messages in content://sms/inbox?


Do all new messages automatically go in content://sms/inbox or do we have to update it manually ?

No, those messages will not be written to the inbox automatically. The default app is responsible for saving all incoming SMS to the Provider. Though there is no requirement for the default app to do so, if it doesn't save them there, then other apps that query the Provider to read existing messages just won't see them. This would explain why your inbuilt SMS app doesn't see the new messages received while yours is the default.

The only message writes that are handled automatically by the system are for outgoing SMS sent by non-default apps. All other inserts, updates, and deletes are left up to the default app.



Is it necessary to forward new messages to other apps listening for new SMS received?

Not specifically, as it were. Any non-default app that is interested in getting messages as they arrive should be listening for the SMS_RECEIVED broadcast, and the system will send that automatically. Such apps have direct access to the messages, since they're attached to the broadcast Intents as extras.

Beyond that, pretty much the only other (practical) way for non-defaults to read messages, or to be notified of changes, is through the Provider, so as long as you're saving the messages there, such apps are covered, as well.



Related Topics



Leave a reply



Submit