问题描述
在网络和计算器包含几个示例如何使用ACTION_GET_CONTENT意图获取其它Android应用程序的文件(例如,使用它作为电子邮件附件)。但是,做什么样的班我要实现创造了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).
时ContentProvider的正确的解决方案?而且我有什么要添加到我的AndroidManifest.xml?
Is a ContentProvider the right solution? And what do I have to add to my AndroidManifest.xml?
推荐答案
几个小时的网络搜索后,我发现了以下解决方案。
After some hours of web search I found the following solution.
-
实施的活动处理的意图。在使用以下或更具体的code:
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();
添加以下的清单:
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>
这篇关于如何为Intent.ACTION_GET_CONTENT内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!