Skip to content

Instantly share code, notes, and snippets.

@mandric
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mandric/11287748 to your computer and use it in GitHub Desktop.
Save mandric/11287748 to your computer and use it in GitHub Desktop.

Intro

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.

Settings

No new settings should be required for this feature.

Manage SMS result data

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.

Solution

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 to null then update value when smsSentReceiver is triggered.
  • sent_result_message - initialize to empty string and update when smsSentReceiver is triggered.
  • delivery_result_code - initalize to null 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.

Sent

  • Activity.RESULT_OK
  • SmsManager.RESULT_ERROR_GENERIC_FAILURE
  • SmsManager.RESULT_ERROR_NO_SERVICE
  • SmsManager.RESULT_ERROR_NULL_PDU
  • SmsManager.RESULT_ERROR_RADIO_OFF

Delivered

  • Activity.RESULT_OK
  • Activity.RESULT_CANCELED

Backwards Compatibility

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.

User Interface

The Sent Box UI needs an update based on the result data. See Issue 120 for more information.

Concerns

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment