1

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!

Cyph3rCod3r
  • 1,978
  • 23
  • 33
  • 1
    I unfortunately don't know the answer, but can say that it is quite easy to check it yourself. Probably even faster than waiting for the answer here – Vladyslav Matviienko Jul 24 '18 at 05:14
  • @VladyslavMatviienko I just figured out you are responsible for writing the SMS for both types to provider. Looking for more specific set of rules to follow – Cyph3rCod3r Jul 24 '18 at 05:30
  • https://stackoverflow.com/questions/28853979/sms-doesnt-save-on-kitkat-4-4-already-set-as-default-messaging-app/28854600#28854600 this by mike again :D – Cyph3rCod3r Jul 24 '18 at 05:31

1 Answers1

3

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).

Mike M.
  • 38,532
  • 8
  • 99
  • 95
  • Thanks Mike, Can you link me to the documentation if any ? – Cyph3rCod3r Jul 24 '18 at 05:20
  • Well, I just noticed that you linked the blog page that explained the default app requirements when it was introduced in KitKat. That's pretty much the _de facto_ documentation for this, and I thought it explained it there. I'll have a read through it again, and if it's not there, I'll try to find something official. It's been so long, I'm not sure how I originally learned it. – Mike M. Jul 24 '18 at 05:25
  • Thanks for the help. I'd dig deep more into AOSP maybe – Cyph3rCod3r Jul 24 '18 at 05:27
  • 1
    OK, the outgoing message rules are explained under the section labeled __Disable features when not the default SMS app__ – "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)." I'm not seeing anything there that explicitly mentions anything about writing incoming messages, but that's kind of implied, I suppose, because it's always been an app that's been responsible for writing those, and only... – Mike M. Jul 24 '18 at 05:35
  • ...the default app has write access to the Provider, anymore. – Mike M. Jul 24 '18 at 05:36
  • Yea I had a confusion on that but now I am clear. Even The AOSP is trying to to save it! Thanks Alot Guys https://android.googlesource.com/platform/packages/apps/Messaging/+/master/src/com/android/messaging/receiver/SmsReceiver.java – Cyph3rCod3r Jul 24 '18 at 06:10
  • Ah, yeah, if I'd've known that source code would've sufficed, I coulda linked ya right there. :-) I've dug through that a bunch. Anyhoo, I found the official word on this in the 4.4 API release notes, so I'll update my answer with the relevant quotes. Cheers! – Mike M. Jul 24 '18 at 06:15
  • 1
    Thanks again for quick replies bro – Cyph3rCod3r Jul 24 '18 at 06:18
  • @Mike.M There is No MESSGE_TYPE_DELIVERED, How do we identify delivered SMSes? – Cyph3rCod3r Aug 02 '18 at 09:53
  • 1
    That's stored in the `Telephony.Sms.STATUS` (`"status"`) column, and it's value is one of `STATUS_NONE` (`-1`), `STATUS_COMPLETE` (`0`), `STATUS_PENDING` (`32`), or `STATUS_FAILED` (`64`) – Mike M. Aug 02 '18 at 10:07
  • ohh Okay. So i will mark that status complete in DeliveredBroadcast ! Thanks – Cyph3rCod3r Aug 02 '18 at 10:26
  • 1
    Yep, but make sure you're getting the delivery status correctly. `getResultCode()` is not the right way to do that for delivery reports. Have a look at the `SmsResultReceiver` in [my answer here](https://stackoverflow.com/a/24845193). The `Intent` you get in the Receiver has a single PDU on it that you need to create an `SmsMessage` from, and then call `getStatus()` on that. Just FYI. Cheers! – Mike M. Aug 02 '18 at 10:32
  • 1
    Thanks Man! I was just manually setting the status to complete as soon as I was receiving that action. I was really not aware of this. – Cyph3rCod3r Aug 03 '18 at 08:22