如何为Intent.ACTION_GET_CONTENT内容 [英] How to provide content for Intent.ACTION_GET_CONTENT

查看:547
本文介绍了如何为Intent.ACTION_GET_CONTENT内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在网络和计算器包含几个示例如何使用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的正确的解决方案?而且我有什么要添加到我的Andr​​oidManifest.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.

  1. 实施的活动处理的意图。在使用以下或更具体的code:

  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();

  • 添加以下的清单:

  • 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内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆