This document expands on some of the technical details of SMSSync Issue 120 and proposes a solution for managing result data of outgoing SMS messages sent by SMSSync.
No new settings should be required for this feature.
Currently there is a problem in ProcessSms.sendSms because we send an SMS first then create a message then save it to the Sent Box using the code below.
sms.sendMultipartTextMessage(sendTo, null, parts, sentIntents, deliveryIntents);
// Get current Time Millis
final Long timeMills = System.currentTimeMillis();
// Log to sent table
Message message = new Message();
message.setBody(msg);
message.setTimestamp(timeMills.toString());
message.setFrom(sendTo);
postToSentBox(message, TASK);
The intents are broadcast but nothing is done with the result data. We need to manage the result data on messages locally.
Modify the intent receivers smsSentReceiver
and smsDeliveredReceiver
in
PendingMessages,
change the context to include the message objects then manage their result
data. The receivers do not make http requests, they only deal with managing
the local data.
Manage new properties on a Message object:
sent_result_code
- initalize tonull
then update value when smsSentReceiver is triggered.sent_result_message
- initialize to empty string and update when smsSentReceiver is triggered.delivery_result_code
- initalize tonull
then update value when smsDeliveryReceiver is triggered.delivery_result_message
- initialize to empty string and update when smsDeliveryReceiver is triggered.uuid
- set this value when first saving the message or posting to Sent Box.
In ProcessSms.sendSms
create the new message object and pass to the intent
context before sending the SMS.
For code
properties use the raw value from the Android SmsManager
API
or whatever the getResultCode
value is in the Intent receiver.
For message
properties use the translated message string from SMSSync.
The full list of supported result states taken from PendingMessages is below and each has a unique result code and message.
- Activity.RESULT_OK
- SmsManager.RESULT_ERROR_GENERIC_FAILURE
- SmsManager.RESULT_ERROR_NO_SERVICE
- SmsManager.RESULT_ERROR_NULL_PDU
- SmsManager.RESULT_ERROR_RADIO_OFF
- Activity.RESULT_OK
- Activity.RESULT_CANCELED
For people upgrading they won't notice a difference here, messages will still be posted to the Sent Box, only difference is the message will also be updated with result data when available.
The Sent Box UI needs an update based on the result data. See Issue 120 for more information.
Rather than use the literal return code value from the Android API we might considering mapping the return code to a string in case the Android API changes later and the Messages object API needs to remain consistent.