Android SMS activity doesn't fill phone number

Today while fixing a bug for our current project we develop for the Android phone I found a strange behavior when trying to launch the phone's SMS sender activity. For those of you non-Android-devs, Android has the concept of Intents.

An intent is an abstract description of an operation to be performed. [...]
(from the Android docs)

This is a really nice mechanism. Basically you launch an Intent, specifying what you'd like to do and those activities out there which may be able to respond to your needs will answer. (a bit simplified of course ;) )

So in our code we launched the phones SMS sender activity by specifying the intent as
Intent smsIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("tel:3330349"));
smsIntent.setType("vnd.android-dir/mms-sms");

startActivity(smsIntent);
The problem as you can see:

...the phone number that has been passed in the intent-uri is not displayed on the SMS activity as it should. I searched a bit around and well...there shouldn't be "tel:...." in the Uri but rather "smsto:...". Fair enough, although by specifying the type of the intent I'd expect to get it anyway. So what I did is to change the intent Uri to..
Intent smsIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("smsto:3330349"));
smsIntent.setType("vnd.android-dir/mms-sms");

startActivity(smsIntent);
..expecting to get it to work now: nothing. Still the same result, the activity opens but there's no phone number displayed. So...?! *confused*
Well, I found that you basically have the following possibilities.
  1. Just specify the Uri. Ok, it's enough, you have all of the needed information encoded in it, but again, additionally specifying the intent type shouldn't be a problem.
    Intent smsIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("smsto:3330349"));
    //smsIntent.setType("vnd.android-dir/mms-sms");

    startActivity(smsIntent);
  2. Specify the phone number by adding it to the intent bundle data.
    Intent smsIntent = new Intent(Intent.ACTION_VIEW);
    smsIntent.putExtra("address", "3330349");
    smsIntent.setType("vnd.android-dir/mms-sms");

    startActivity(smsIntent);
Both will bring you the expected result


I understand, specifying the uri containing the "smsto" and the type is somehow redundant information, but anyway I wouldn't expect that it doesn't work at all.
Kindle

Comments

0

Your ad here?