android - 使用什么样的 Intent 在应用程序之间进行选择,以及如何监听它?

标签 android android-intent

我正在尝试创建一种文件管理器,以允许用户将文件(从文件管理器)上传到互联网。

我想了解如何触发此应用程序。

例如: 当使用 Gmail 并按下添加附件按钮时,Android 会显示两个应用程序(Gallery 和 FileExpert)供我从中选择内容。

  • 这是如何实现的?
  • 广播什么样的 Intent(如果使用 Intent)?
  • 可以调用Gallery和FileManager是什么样的对象 按添加附件按钮?

最佳答案

你是对的,这是使用 Intents 实现的。特别是,调用应用程序(示例中的 Gmail)会发送上传一个或多个文件的 Intent 。对于选择文件, Intent 是 Intent.ACTION_GET_CONTENT .

要将您的应用添加到处理此 Intent 的应用程序列表中,您需要在 list 中指定它。根据this documentation ,它看起来像这样:

<activity android:name=".ui.MyActivity" >
    <intent-filter>
        <action android:name="android.intent.action.ACTION_GET_CONTENT" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:mimeType="*/*" />
    </intent-filter>
</activity>

关于android - 使用什么样的 Intent 在应用程序之间进行选择,以及如何监听它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18378588/

相关文章:

android - NestedScrollview 和 ConstraintLayout 可以一起使用吗?

Android Studio 未启动 : Fatal error initializing 'com. intellij.util.indexing.FileBasedIndex

android - 在管理应用程序中禁用或删除强制停止

java - fragment 替换错误

android - 使用 Android Intent 发送基于 HTML 的电子邮件正文

java - 将 CameraBridgeViewBase 作为服务运行以使用 OpenCV 在后台进行运动检测

android - 设置 Google Analytics 以触发具有维度更改的新 session

android - Gradle - 无法从支持库中找到符号方法

android - 如何动态设置 Android 向上按钮的 Activity ?

java - 将音乐文件从一个应用程序发送到另一个应用程序