android - 如何为 Intent.ACTION_GET_CONTENT 提供内容

标签 android android-intent android-contentprovider

Web 和 stackoverflow 包含几个示例如何使用 ACTION_GET_CONTENT Intent 从另一个 Android 应用程序获取文件(例如,将其用作电子邮件附件)。但是我必须实现什么样的类才能创建为 ACTION_GET_CONTENT 事件提供内容的应用程序,例如我可以选择此应用程序(例如,用于选择电子邮件附件)。

ContentProvider 是正确的解决方案吗?我必须向我的 AndroidManifest.xml 添加什么?

最佳答案

经过几个小时的网络搜索,我找到了以下解决方案。

  1. 实现一个 Activity 处理 Intent 。在其中,使用以下或更具体的代码:

    Uri resultUri = // the thing to return
    Intent result = new Intent();
    result.setData(resultUri);
    setResult(Activity.RESULT_OK, result);
    finish();
    
  2. 将以下内容添加到 list 中:

    <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>
    

关于android - 如何为 Intent.ACTION_GET_CONTENT 提供内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11933984/

相关文章:

android - 如何在 android 中为 textview 使用 `Open Sans` 字体样式?

android - 智能 watch 如何让按钮打开手机中的文件

Android ContentProvider URI 方案通知 CursorAdapters 监听 OUTER JOIN 查询

android - IllegalArgumentException : the bind value at index 1 is null

android - OSMDroid 叠加多个静态和一个动态

java - 安卓|单选按钮不会做任何事情并保持按下状态

java - 如何在 Android 应用程序中全局访问另一个类的 Activity?

android - 用于在未启动的android和服务器之间同步数据的SyncService

java - AsyncTask 中通过代码旋转屏幕崩溃

android - AlarmManager 有时不唤醒手机 (XPERIA)