针对特定文件扩展名的 Android SEND 操作 Intent 过滤器?

标签 android intentfilter

我正在创建一个必须出现在“共享”菜单上的应用程序,但我只希望它在共享的文件具有“foo”扩展名 (filename.foo) 时出现。 我必须补充一点,我不知道文件是什么 mime 类型,而且我是 android 的新手。

这是 list 中的代码:

<intent-filter>
    <action android:name="android.intent.action.SEND" />
    <category android:name="android.intent.category.DEFAULT" />
    <data android:scheme="file" />
    <data android:mimeType="*/*" />
    <data android:pathPattern=".*\\.foo" />
    <data android:host="*" />
</intent-filter>

我在“pathPattern”这一行收到警告,说的是:

App is not indexable by Google Search; consider adding at least one Activity with an ACTION-VIEW intent filter.

所以我假设代码确实有效,但使用的是 VIEW 操作,而不是 SEND 操作。

最佳答案

I only want it to appear when the file that is being shared has a 'foo' extension (filename.foo)

Android 中不共享文件。内容是共享的。内容没有文件扩展名——它有一个 MIME 类型。 Android 不支持您想要的内容。

This is the code inside the manifest

ACTION_SEND不使用 Uri .你所有的<data>元素无效,<data android:mimeType="*/*" /> 除外.

I got a waring on the "pathPattern" line, saying this

在添加此 <intent-filter> 之前,您有同样的警告.您将在全新的 Android Studio 项目中收到相同的警告。与你的<intent-filter>无关只是来自 IDE 的恼人噪音。

关于针对特定文件扩展名的 Android SEND 操作 Intent 过滤器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57599848/

相关文章:

android - 如果是手机或平板电脑 (Android 2.1+),则一个 APK 会启动不同的 Activity

Java android性能数组: access class getter directly or create local copy

Java 继承 - sibling 的重写方法问题

java - 如何正确检查2 -3个条件?

android - sharedpreferences 帮助程序类上的 nullPointerException 运行测试时

没有 Intent 过滤器的Android BroadcastReceiver

android - 无法将 "addAction"设置为 android 中的 IntentFilter

android - 如何在收到广播 Intent CONNECTIVITY_CHANGE 后更新小部件

android - 将应用程序与 Google 搜索结果和 Chrome 集成

android - 在 Android 应用程序中打开文件的 Intent 过滤器出现问题