简体   繁体   English

意图仅过滤文件

[英]Intent filter for files only

in our app, we want to appear in the "Share via" menu. 在我们的应用中,我们希望出现在“分享通过”菜单中。 So we added this intent-filter to our activity : 所以我们在我们的活动中添加了这个intent-filter:

<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 : 然而,意图过滤器并不完全符合我们想要的目标:

  1. we want to appear in the menu for all files, whatever there mime type is 我们希望出现在所有文件的菜单中,无论mime类型是什么
  2. 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. 到目前为止,如果用户想要共享一个简单的文本,因为它的mime类型将是text / plain,我们的应用程序出现在菜单中,我们不想要它。

What would the correct intent-filter be for all files and only for files ? 对于所有文件和仅文件,正确的intent-filter会是什么?

Thanks in advance. 提前致谢。


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. 我们尝试添加scheme = file和host =“”或“*”,并且它不起作用,因为许多app使用scheme = content来共享基于文件的内容。

we want to appear in the menu for all files, whatever there mime type is 我们希望出现在所有文件的菜单中,无论mime类型是什么

Try a MIME type of */* . 尝试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. 到目前为止,如果用户想要共享一个简单的文本,因为它的mime类型将是text / plain,我们的应用程序出现在菜单中,我们不想要它。 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. 我们尝试添加scheme = file和host =“”或“*”,并且它不起作用,因为许多app使用scheme = content来共享基于文件的内容。

Then have two <data> elements, one for a scheme of content and one for a scheme of file . 然后有两个<data>元素,一个用于content方案,另一个用于file方案。

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

However, bear in mind that a content scheme does not mean that it is necessarily a file. 但是,请记住, content方案并不意味着它必然是文件。

  1. If you want to be invoked for any mime type, don't place a single mine type in the filter 如果要为任何mime类型调用,请不要在过滤器中放置单个mine类型
  2. scheme="file" is the answer to run only on files. scheme="file"是仅对文件运行的答案。 Now if the 3rd party applicaiton pass the data as content , then it is (by defiinition) not a file any more 现在,如果第三方应用程序将数据作为content传递,那么(通过定义)不再是文件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM