shoren
shoren

Reputation: 941

what is the difference between ACTION_SENDTO and ACTION_VIEW when sending sms?

I have an application that sends messages to a specified contact. Right now I use

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("smsto:" + phoneNumber));

to send messages, and it works great on the emulator and on my N1. I got complaints from users with HTC incredible that they get force close from android.mms application when they use it. I did more digging and I see there are many ways for sending messages. For example

Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.parse("smsto:" + phoneNumber));

And also

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.putExtra("address", phoneNumber);
intent.setType("vnd.android-dir/mms-sms");

They all seem to work exactly the same on the emulator and on my device, and I could not find anything official about the correct, generally supported way. Any ideas?

Upvotes: 10

Views: 10089

Answers (2)

EboMike
EboMike

Reputation: 77752

The intent describes your intent. What do you want to do? Check out the documentation on Intent http://developer.android.com/reference/android/content/Intent.html

In your case, you want to send something, so ACTION_SENDTO definitely sounds a lot more appropriate than ACTION_VIEW (which is used to view an existing record).

Unfortunately, there is no official registry for what intents are available - the fearless guys at OpenIntents started a Wiki-style registry at http://www.openintents.org/en/intentstable, but it's crowdsourced and very incomplete. In the end, it's about how the application that supports the intent handles it.

In your case, the standard Android messaging application happens to handle ACTION_VIEW, but HTC's custom app doesn't. My best advice is to use ACTION_SENDTO, and to handle an exception and display an error message. Remember that the user may have third-party SMS apps installed.

Upvotes: 4

Macarse
Macarse

Reputation: 93163

I will try to see how they did it on the Contacts apps.

In the past I had lot's of compatibility issues with the HTC Hero. I always ended up writing the code that worked on phones with the Sense UI. I found out that if the code works there, it would work on every android device :).

Upvotes: 0

Related Questions