Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

android

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?

like image 320
shoren Avatar asked Jul 27 '10 05:07

shoren


People also ask

What does Android Intent action VIEW do?

A common intent action is ACTION_VIEW, which you use when you have some information that an activity can show to the user, such as a photo to view in a gallery app, or an address to view in a map app. You can specify the action for an intent in the intent constructor, or with the setAction() method.

How do I send a message using intent?

Built-in SMS applicationIntent sendIntent = new Intent(Intent. ACTION_VIEW); sendIntent. putExtra("sms_body", "default content"); sendIntent. setType("vnd.

What is the use of intent createChooser () method?

Most commonly, ACTION_SEND action sends URL of build-in Browser app. While sharing the data, Intent call createChooser() method which takes Intent object and specify the title of the chooser dialog. Intent. createChooser() method allows to display the chooser.

How do I transfer data from one Android app to another?

Android uses the action ACTION_SEND to send data from one activity to another, even across process boundaries. You need to specify the data and its type. The system automatically identifies the compatible activities that can receive the data and displays them to the user.


1 Answers

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.

like image 109
EboMike Avatar answered Oct 14 '22 02:10

EboMike