flutter - 使用 Flutter App 打开自定义文件扩展名
问题描述
如何(.foo)
为 FlutterApp分配(或关联)自定义文件扩展名(BarBaz)
,然后在用户从文件管理器中选择文件时,对话框会显示此应用程序以打开文件。后来我的应用程序可以在其中管理这个文件,并处理它的内容。
就像音频播放器一样,将音频文件关联到它,然后打开它。
解决方案
我已经尝试了很多这样的变体,但没有一个奏效。几天后,我找到并尝试了这个对我有帮助的。
所以,我通过将此代码添加到我的 /android/app/src/main/AndroidManifest.xml来解决它:
<manifest>
...
<application>
...
<activity>
...
<intent-filter android:priority="999">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.OPENABLE" />
<data android:host="*" />
<data android:mimeType="application/octet-stream" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\.YOUR_CUSTOM_EXTENSION" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.YOUR_CUSTOM_EXTENSION" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.YOUR_CUSTOM_EXTENSION" />
<data android:pathPattern=".*\\..*\\..*\\.YOUR_CUSTOM_EXTENSION" />
<data android:pathPattern=".*\\..*\\.YOUR_CUSTOM_EXTENSION" />
<data android:pathPattern=".*\\.YOUR_CUSTOM_EXTENSION" />
<data android:scheme="content" />
</intent-filter>
...
</activity>
</application>
</manifest>
推荐阅读
- java - 您将如何为采用 FileInputStream 的方法制作测试用例?
- vb6 - 将万亿数字转换为二进制
- php - 在我的 wordpress 网站上出现这些错误(rankmath 404 Monitor)
- r - 错误:在 Shiny 应用程序中,只有字符串可以转换为符号
- c - 解析简单的数学表达式
- git - .gitignore 问题我只需要使用 !*02.* 模式跟踪文件,但我只能排除它们而不是使用 !*02.* 跟踪它们
- python - 为什么 python3 ttk 复选框使用的任何选项都会出错?
- angular - 输入中的自动完成建议为光标后的灰色字母,而不是选择弹出窗口
- javascript - 对按键作出反应,只执行一次 setTimeout
- c++ - 用 CRTP 实例化和注册派生类的最佳方法?