android – 仅用于文件的意图过滤器

在我们的应用程序中,我们要显示在“通过分享”菜单中.所以我们将这个意图过滤器添加到我们的活动中:
<intent-filter>
    <action android:name="android.intent.action.SEND" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:mimeType="application/*" />
    <data android:mimeType="audio/*" />
    <data android:mimeType="image/*" />
    <data android:mimeType="text/*" />
    <data android:mimeType="video/*" />
</intent-filter>

它的工作原理,我们的应用程序出现在共享菜单中.

然而,意图过滤器并不完全符合我们想要实现的目标:

>我们想出现在所有文件的菜单中,无论mime类型是什么
>我们只想显示文件.到目前为止,如果用户想要分享一个简单的文本,因为它的mime类型将是文本/简单的,我们的应用程序出现在菜单中,我们不想要它.

所有文件和文件的正确意图过滤器是什么?

提前致谢.

我们尝试添加scheme = file和host =“”或“*”,它不起作用,许多应用程序使用scheme = content来共享基于文件的内容.

解决方法

we want to appear in the menu for all files,whatever there mime type is

尝试一个MIME类型的* / *.

we want to appear only for files. And up to now,if the user wants to share a simple text,as its mime type will be text/plain,our app appears in the menu and we don’t want it. We tried to add scheme=file and host=”” or “*” and it doesn’t work as many app use a scheme=content to share file based content.

然后有两个< data>元素,一个用于内容方案,一个用于文件方案.

<data android:mimeType="*/*" />
<data android:scheme="content" />
<data android:scheme="file" />

但是,请记住,内容方案并不意味着它必然是一个文件.

相关文章

Android 如何解决dialog弹出时无法捕捉Activity的back事件 在...
Android实现自定义带文字和图片的Button 在Android开发中经常...
Android 关于长按back键退出应用程序的实现最近在做一个Andr...
android自带的时间选择器只能精确到分,但是对于某些应用要求...