Android: send SMS (using outgoing messages)

I am working on an SMS application for Android, which undoubtedly needs to send SMS messages (go figure !;)

Now I know that there are many sources on the network that describe the use of SmsManager to send SMS messages ... But, apparently, when using this method, SMS messages are not stored in the "SENT" folder .. This is the main requirement for the application SMS

How to add an entry (messages) to Outbox so that it is sent (and automatically saved in the SENT folder) .... What will 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 ...

+3
source share
4 answers

But apparently, when using this method, SMS messages are not saved in the "SENT" folder ... which is the basic requirement for an SMS application.

The concept of the SENT folder is a function of the application, not the operating system. If you want to create your own SMS client application, create your own "SENT" folder as a function of this application. You know what messages you send, so you can store them wherever you want (for example, an SQLite database).

SMS- "SENT" SMS-, SmsManager. ACTION_SENDTO , SMS, .

+1

. ... sms-

ContentValues values = new ContentValues();

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

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

ppl, , , ... ..

+4

SMS SMS, SMS ( GUI), , ContentResolver android.permission.WRITE_SMS

0

6.0 7.0 com.android.phone , . , , .

AVD. . persistSentMessageIfRequired() com.android.internal.telephony.SMSDispatcher.

Only this application or the default SMS application has write permission for the SMS content provider. When you send it using the SMS application, it calls insert()directly. When you use SmsManagerin your application, the system application com.android.phonesomehow receives a notification, sends, and then saves the sent message. Here's the callstack (I haven't dug yet):

  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 sending an SMS, the application sends a message Handlerto 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)
0
source

Source: https://habr.com/ru/post/1753154/


All Articles