意图过滤器仅用于文件 [英] Intent filter for files only
问题描述
在我们的应用中,我们希望出现在共享方式"菜单中.因此,我们将此intent-filter添加到了我们的活动中:
in our app, we want to appear in the "Share via" menu. So we added this intent-filter to our activity :
<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>
它可以工作,并且我们的应用程序出现在共享"菜单中.
It works and our app appears in the Share menu.
但是,意图过滤器并不能完全实现我们想要实现的目标:
Nevertheless, the intent filter doesn't do exactly what we want to achieve :
- 我们希望出现在所有文件的菜单中,无论mime类型是什么
- 我们只希望出现在文件中.到目前为止,如果用户希望共享一个简单的文本,因为它的mime类型将是text/plain,则我们的应用程序会出现在菜单中,而我们不希望它.
对于所有文件,仅对于文件,正确的意图过滤器是什么?
What would the correct intent-filter be for all files and only for files ?
谢谢.
我们尝试添加scheme = file和host ="或"*",但由于许多应用程序使用scheme = content共享基于文件的内容,因此无法正常工作.
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.
推荐答案
我们希望出现在所有文件的菜单中,无论MIME类型是什么
we want to appear in the menu for all files, whatever there mime type is
尝试使用MIME类型*/*
.
Try a MIME type of */*
.
我们只希望出现在文件中.到目前为止,如果用户希望共享一个简单的文本,因为它的哑剧类型将是文本/纯文本,则我们的应用程序会出现在菜单中,我们不希望它出现.我们尝试添加scheme = file和host ="或"*",但由于许多应用程序使用scheme = content共享基于文件的内容,因此无法正常工作.
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>
元素,一个用于content
方案,一个用于file
方案.
Then have two <data>
elements, one for a scheme of content
and one for a scheme of file
.
<data android:mimeType="*/*" />
<data android:scheme="content" />
<data android:scheme="file" />
但是,请记住,content
方案并不意味着它一定是文件.
However, bear in mind that a content
scheme does not mean that it is necessarily a file.
这篇关于意图过滤器仅用于文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!