android - 使我的应用程序作为文件选择器对话框中的一个选项可用

标签 android android-intent intentfilter

如何使我的应用程序在文件选择器的“打开自”对话框中可用?以及如何在 Activity 代码中处理该请求?

这是我希望我的应用程序作为一个选项出现的对话框的屏幕截图(此对话框来自于将文件上传到谷歌驱动器):

enter image description here

最佳答案

您可以在 mainfest 文件的 intent-filter 中指定 mimeType。 您的应用程序将被添加到共享列表。

例如,您需要添加用于文本共享的应用,然后使用 mimeType="text/plain"

  <activity android:name="ShareActivity">
    <intent-filter>
        <action android:name="android.intent.action.SEND"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <data android:mimeType="text/plain"/>
    </intent-filter>
</activity>

处理共享:

在您的 Activity 的 onCreate 方法中编写此代码( Activity 在 mainfest 中声明,带有 intent 过滤器(以上))

    if (Intent.ACTION_SEND.equals(intent.getAction()))
    {
        Uri uri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);

       //here you will get data which is shared.
    }

关于android - 使我的应用程序作为文件选择器对话框中的一个选项可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36052569/

相关文章:

java - 安卓转接电话

android - 自定义方案的 Intent-filter pathPattern

android - 调用 Intent 过滤器

android - BroadcastReceiver不接收来自外部链接的Intent

android - 我可以使用任何 Android 手机进行应用程序开发吗?

android - 如何从android中的一组Whatsapp中获取联系人?

android - ClusterManager 不重绘标记

android - iOS App 中的文本渲染

java - 调用 stopService() 时 Android 服务不会停止

android - 从 Android 上的 SD 卡中选择歌曲并播放