Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to provide content for Intent.ACTION_GET_CONTENT

The web and stackoverflow contain several examples how to get a file from another Android app (e.g., to use it as email attachment) using an ACTION_GET_CONTENT intent. But what kind of class do I have to implement to create an application providing content for the ACTION_GET_CONTENT event such as I can choose this app (e.g., for selecting an email attachment).

Is a ContentProvider the right solution? And what do I have to add to my AndroidManifest.xml?

like image 753
Claas Wilke Avatar asked Aug 13 '12 12:08

Claas Wilke


1 Answers

After some hours of web search I found the following solution.

  1. Implement an Activity handling intents. Within, use the following or more specific code:

    Uri resultUri = // the thing to return
    Intent result = new Intent();
    result.setData(resultUri);
    setResult(Activity.RESULT_OK, result);
    finish();
    
  2. Add the following to the Manifest:

    <activity
        android:name="ActivityName"
        android:label="Some label" >
        <intent-filter>
            <action android:name="android.intent.action.GET_CONTENT" />
            <category android:name="android.intent.category.OPENABLE" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="*/*" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.PICK" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="*/*" />
        </intent-filter>
    </activity>
    
like image 181
Claas Wilke Avatar answered Sep 22 '22 22:09

Claas Wilke