4

I'm working on an SMS Application for Android, which undoubtedly needs to send SMSes (go figure! ;)

Now, i know there are a plenty of sources on the net that describe using the SmsManager to send SMSes...But, apparently, when using that method, the SMSes aren't stored in the "SENT" Folder...which is kind of a basic requirement for an SMS application.

How do i add an entry (of a message) into the "Outbox", so that it gets sent (and stored in the SENT Folder Automatically).... What would be the Values of the fields "_id,threadid,read,status,type,service_center" (Attributes of the message table)??

Any other alternatives are also welcome. :) Thanks in Advance...

st0le
  • 33,375
  • 8
  • 89
  • 89

3 Answers3

4

I had been looking for a work around this issue. Add the following lines of code after sending the sms... this will make an entry in the outbox of native sms application

ContentValues values = new ContentValues();

values.put("address", number);
values.put("body", desc); 

getApplicationContext().getContentResolver().insert(Uri.parse("content://sms/sent"),    values);

i would like to get help from ppl who could tell how to use this content provider to make entry for multiple receivers... Thanks..

Achin Kumar
  • 777
  • 6
  • 11
1

But, apparently, when using that method, the SMSes aren't stored in the "SENT" Folder...which is kind of a basic requirement for an SMS application.

The concept of a "SENT" folder is a feature of an application, not the operating system. If you wish to create your own SMS client application, create your own "SENT" folder as a feature of that application. You know what messages you are sending, so you can store them wherever you like (e.g., SQLite database).

If you want to send SMS messages and have them appear in the "SENT" folder of the user's chosen SMS client, don't use SmsManager. Instead, use ACTION_SENDTO and have the message be sent by the user's chosen SMS client, as is demonstrated by this sample project.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I've explored that option, but i would like to use the internal "SENT" Folder...So even though the user may use my application, his messages are still visible in the inbuilt Messaging App. – st0le Jul 06 '10 at 04:04
  • I can't to use the ACTION_SENDTO, it has to be using my GUI...there are additional features my app support... – st0le Jul 06 '10 at 04:19
  • @st0le: there is no single "inbuilt Messaging App" in Android. HTC Sense has one. MOTOBLUR has one. Other OEM layers (e.g., Sony Ericsson's Rachael) probably have theirs. Plus, there is the one that is part of the open source project and will appear on Google Experience devices (e.g., Nexus One). – CommonsWare Jul 06 '10 at 10:59
  • @Mark, went with my own SQlit Database... :) – st0le Jul 07 '10 at 04:03
  • I used `android.telephony.SmsManager.sendTextMessage`, and messages were appearing in the outbox(in a Samsung Galaxy something, and an HTC phone, don't remember the exact model). According to your answer they modified the android OS in such a way that it stores every message sent and provide the sent messages to the apps which require it? –  Mar 10 '13 at 19:49
  • @CommonsWare I read this article http://www.androidguys.com/2009/12/14/code-pollution-reaching-past-the-sdk/, which you mentioned in another similar thread. I am sorry, I down-voted this answer due to my lack of knowledge. –  Mar 11 '13 at 10:34
  • Can you please edit this answer so that I can remove my downvote? –  Mar 11 '13 at 10:34
0

At least on 6.0 and 7.0 the system app com.android.phone is responsible for storing the messages sent by other apps. Unfortunately, this functionality is broken by some manufacturers and this is why we don't see sent messages.

It does work on AVD though. See the method persistSentMessageIfRequired() in com.android.internal.telephony.SMSDispatcher.

Only this app or the selected default SMS app has a write permission to the SMS content provider. When you send it using the SMS app, it calls insert() directly. When you use SmsManager in your app, the system app com.android.phone somehow gets notified, performs the sending and then stores the sent message. Here's the callstack (I didn't dig further):

  at android.os.Handler.obtainMessage(Handler.java:293)
  at com.android.internal.telephony.gsm.GsmSMSDispatcher.sendSmsByPstn(GsmSMSDispatcher.java:291)
  at com.android.internal.telephony.gsm.GsmSMSDispatcher.sendSms(GsmSMSDispatcher.java:274)
  at com.android.internal.telephony.SMSDispatcher.sendRawPdu(SMSDispatcher.java:999)
  at com.android.internal.telephony.gsm.GsmSMSDispatcher.sendText(GsmSMSDispatcher.java:198)
  at com.android.internal.telephony.ImsSMSDispatcher.sendText(ImsSMSDispatcher.java:206)
  at com.android.internal.telephony.IccSmsInterfaceManager.sendTextInternal(IccSmsInterfaceManager.java:452)
  at com.android.internal.telephony.IccSmsInterfaceManager.sendText(IccSmsInterfaceManager.java:393)
  at com.android.internal.telephony.UiccSmsController.sendTextForSubscriber(UiccSmsController.java:136)
  at com.android.internal.telephony.ISms$Stub.onTransact(ISms.java:201)
  at android.os.Binder.execTransact(Binder.java:565)

After the SMS is sent, the app posts a Handler message to itself:

     at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1343)
     at com.android.providers.telephony.SmsProvider.insertInner(SmsProvider.java:618)
     at com.android.providers.telephony.SmsProvider.insert(SmsProvider.java:442)
     at android.content.ContentProvider$Transport.insert(ContentProvider.java:264)
     at android.content.ContentResolver.insert(ContentResolver.java:1274)
     at com.android.internal.telephony.SMSDispatcher$SmsTracker.persistSentMessageIfRequired(SMSDispatcher.java:1445)
     at com.android.internal.telephony.SMSDispatcher$SmsTracker.persistOrUpdateMessage(SMSDispatcher.java:1476)
     at com.android.internal.telephony.SMSDispatcher$SmsTracker.onSent(SMSDispatcher.java:1537)
     at com.android.internal.telephony.SMSDispatcher.handleSendComplete(SMSDispatcher.java:638)
     at com.android.internal.telephony.SMSDispatcher.handleMessage(SMSDispatcher.java:274)
     at com.android.internal.telephony.gsm.GsmSMSDispatcher.handleMessage(GsmSMSDispatcher.java:108)
     at android.os.Handler.dispatchMessage(Handler.java:102)
     at android.os.Looper.loop(Looper.java:154)
     at android.app.ActivityThread.main(ActivityThread.java:6077)
     at java.lang.reflect.Method.invoke(Native Method)
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
basin
  • 3,949
  • 2
  • 27
  • 63