Android intent filter: add attachment to SMS/MMS m

2019-09-17 20:49发布

问题:

What intent is fired when the user tries to add an attachment to an SMS/MMS message? I tried these and none of them work:

GET_CONTENT with DEFAULT category and "/" mimeType PICK with DEFAULT category and "/" mimeType

I also tried the above with categories OPENABLE and BROWSABLE.

I can't find this documented ANYWHERE. It doesn't seem to be the same intent as the email attachment filter.

Just to clarify, I'm talking about adding my app as an option in the dialog that appears when the user tries to attach something to an SMS or MMS message.

回答1:

Normally user do this to add picture to MMS:

Intent sendIntent = new Intent(Intent.ACTION_SEND); 
sendIntent.putExtra("sms_body", "some text"); 
sendIntent.putExtra(Intent.EXTRA_STREAM, Uri.parse(url));
sendIntent.setType("image/png");

So, you should register your activity for ACTION_SEND action.

You can also filter on intents that have image attached via mime="image/png" filter:

<intent-filter android:icon="drawable resource"
           android:label="string resource"
           android:priority="integer" >
    <action android:name="ACTION_SEND" />
    <data android:mimeType="image/png"/>
</intent-filter>

Update:

To see how MMS app adds attachments see this code: http://www.google.com/codesearch#cZwlSNS7aEw/packages/apps/Mms/src/com/android/mms/ui/ComposeMessageActivity.java&exact_package=android&q=AttachmentTypeSelectorAdapter&type=cs&l=2415

In most cases your app needs to register ACTION_GET_CONTENT action.



回答2:

Turns out, the attachment dialog isn't an intent like the email attachment is. It's an intermediate dialog that controls the type of attachment.

In my case, choosing a type that corresponds to the MIME type (such as image/png) fires the intent and shows my application as one of the choices.

Thanks Peter Knego for a link to the Android source.