How to provide content for Intent.ACTION_GET_CONTENT

The web and stackoverflow contain some examples of how to get a file from another Android application (for example, use it as an email attachment) using the ACTION_GET_CONTENT intent. But what class do I need to implement to create an application that provides content for the ACTION_GET_CONTENT event, for example, I can select this application (for example, to select an email attachment).

Is ContentProvider the right solution? And what should I add to my AndroidManifest.xml?

+7
source share
2 answers

After several hours of web searching, I found the following solution.

  • Implement the intentions of processing actions. Inside, 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(); 
  • 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> 
+15
source

starting from the 18th level of the api level, EXTRA_ALLOW_MULTIPLE can also be set to true, in which case you can send more than one file back to the result. To do this, you need to install it as ClipData:

 resultIntent.setClipData(clipData) 
0
source

All Articles