【发布时间】:2020-12-05 21:27:02
【问题描述】:
如何将自定义文件扩展名 (.foo) 分配(或关联)给 FlutterApp (BarBaz),然后任何时候用户从文件管理器中选择文件,对话框都会显示此应用程序以打开文件。
后来我的应用程序可以在其中管理这个文件,并处理它的内容。
就像一个音频播放器,将音频文件关联到它,然后打开它。
【问题讨论】:
标签: flutter
如何将自定义文件扩展名 (.foo) 分配(或关联)给 FlutterApp (BarBaz),然后任何时候用户从文件管理器中选择文件,对话框都会显示此应用程序以打开文件。
后来我的应用程序可以在其中管理这个文件,并处理它的内容。
就像一个音频播放器,将音频文件关联到它,然后打开它。
【问题讨论】:
标签: flutter
我尝试了很多变体like this,但都没有奏效。 几天后,我找到并尝试了对我有帮助的this one。
所以,我通过将此代码添加到我的 /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>
【讨论】: