开发者

Dealing with differences between phones when Application uses Intent.ACTION_SEND

开发者 https://www.devze.com 2023-02-03 09:40 出处:网络
I have an application that allows the user to send a picture.This picture can be sent via a number of different ways, like g-mail, facebook, flickr, and the one I am interested in, text messaging.When

I have an application that allows the user to send a picture. This picture can be sent via a number of different ways, like g-mail, facebook, flickr, and the one I am interested in, text messaging. When the following code is run, a dialog box pops up with a number of these options available.

       Uri uri = Uri.fromFile(new File(externalDirectory + FILE_DIRECTORY + fileName));      
        Intent intent = new Intent(Intent.ACTION_SEND); 
        intent.putExtra(Intent.EXTRA_STREAM, uri);
        intent.setType("image/png"); 
        startActivity(intent);

On my Droid X, the text messaging option is shown, and this code adds the picture to the MMS perfectly.

On 开发者_如何学运维the emulator, text messaging is chosen automatically (since there are no other options) and once again it works great.

On my Droid Incredible, there is no text messaging option. However, I can manually bring up the built-in text messaging utility, add the picture and then send it. I also downloaded an SMS/MMS app from the market, and afterward the option to use this 3rd party program to send the picture was available from the list.

So, why isn't text messaging an available option on the Droid Incredible? What do I need to do to make it an option, and how do I evaluate this problem (OR UNKNOWN PROBLEMS) with phone types I have no access to?


So, why isn't text messaging an available option on the Droid Incredible?

Because they chose not to offer it.

What do I need to do to make it an option

In the abstract, you can't.

Quoting the Android Compatibility Definition Document:

The Android upstream project defines a number of core applications, such as a phone dialer, calendar, contacts book, music player, and so on. Device implementers MAY replace these applications with alternative versions.

However, any such alternative versions MUST honor the same Intent patterns provided by the upstream project. For example, if a device contains an alternative music player, it must still honor the Intent pattern issued by third-party applications to pick a song.

The catch is, the Messenger app is not considered a "core application" by Google. Hence, device manufacturers are welcome to include their own SMS clients, with their own Intent filters. In the case of the HTC Incredible, apparently they did not include support for MMS via an image/png ACTION_SEND Intent.

Now, IMHO, Messenger probably should be a core application. However, your opinion and mine do not change reality as it stands today.

how do I evaluate this problem (OR UNKNOWN PROBLEMS) with phone types I have no access to

You redefine your application such that it is not a "problem". You have no guarantee that you can send an MMS that way, just as you have no guarantee that a user has a Facebook app installed.

I don't know much about MMS and am uncertain if there is a way other than ACTION_SEND to send an MMS. You might consider poking through the source code to the Messenger app to see how it does it. Then, bake the capability directly into your app. This will require a few extra permissions (SEND_SMS, and probably READ_CONTACTS) and will be annoying to write, but it will be more likely to work across devices.


I did manage to come up with a work around for this, thanks to some help from some other questions on SO.

Basically the key was determining the intent used by HTC, which appears to be the only company (currently) that's modified the android.intent.action.SEND Intent. Here is the code to add the option to the list.

Uri uri = Uri.fromFile(new File(mFile));  
Intent intent = new Intent(Intent.ACTION_SEND); 
intent.putExtra(Intent.EXTRA_STREAM, uri);
intent.setType("image/png"); 

Intent htcIntent = new Intent("android.intent.action.SEND_MSG");
htcIntent.setType("image/png");
htcIntent.putExtra(Intent.EXTRA_STREAM, uri);

Intent chooser = Intent.createChooser(intent, "Send Method");
chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { htcIntent });
startActivity(chooser);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号