1

I am maintaining an app which allows you to share via SMS with the following code:

    String separator = "; ";
    if(android.os.Build.MANUFACTURER.toLowerCase().contains("samsung")){
        separator = ", ";
    }
    StringBuilder uri = new StringBuilder("sms:");
    for (int i = 0; i < nums.length; i++) {
        uri.append(nums[i]);
        if( i < (nums.length -1) )
            uri.append(separator);
    }
    Intent smsIntent = new Intent(Intent.ACTION_VIEW);
    smsIntent.setType("vnd.android-dir/mms-sms");
    smsIntent.setData(Uri.parse(uri.toString()));
    smsIntent.putExtra("sms_body", smsBody);
    startActivityForResult(smsIntent, SMS_SENT_RESULT);

I have noticed the following bizarre behavior (occurs on a Samsung Galaxy S3 and a Kyocera Event, so - I think - not vendor specific):

When one of the phone numbers in nums contains the pound sign ('#'), all numbers after it are dropped. That is, if I try to send a message to 'Andy' at 1-111-111-1111, 'AT&T tech support' at *228#, and 'Betty' at 1-222-222-2222, the constructed URI is "sms:1-111-111-1111; *228#; 1-222-222-2222" but the resulting SMS has only "To: Andy, AT&T tech support".

Is there a workaround for this? Some alternative way of specifying the recipients, maybe, or an accepted style of escaping for Android intent URIs?

Arkaaito
  • 7,347
  • 3
  • 39
  • 56
  • Is there a reason why you send an SMS via intent, rather than just sending it directly? Remember that every phone will have its own SMS app, which may not use the name you expect, and may have different feature sets. – Gabe Sechan Mar 19 '14 at 03:31
  • When you say "may not use the name you expect", do you mean apps that don't support the sms / smsto intent URI scheme? As far as why we're using an intent - our desire is to allow the user to view the SMS and, if they approve, send it themselves rather than triggering it in an automated fashion. As far as I know intents are the only way to get this behavior, though if there's an alternative I'm unaware of, please let me know. (I'm an Android novice.) – Arkaaito Mar 19 '14 at 03:37
  • The other way of getting that behavior would be to write it yourself, but that would be some work. The vnd.xxx mime type is vendor specific. Its something someone wrote for android, and truthfully I haven't seen it before (although I've never tried to launch the SMS app, I always sent my own). There's no promise that the phone's SMS app supports it, and no promise that all those which support it will support multiple recipients. But I did find a better way- check http://stackoverflow.com/questions/19853220/android4-4-can-not-handle-sms-intent-with-vnd-android-dir-mms-sms – Gabe Sechan Mar 19 '14 at 03:43

0 Answers0