gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:16:19 25 4
gpt4 key购买 nike

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com