首页 > 解决方案 > 使用 Flutter App 打开自定义文件扩展名

问题描述

如何(.foo)为 FlutterApp分配(或关联)自定义文件扩展名(BarBaz),然后在用户从文件管理器中选择文件时,对话框会显示此应用程序以打开文件。后来我的应用程序可以在其中管理这个文件,并处理它的内容。

就像音频播放器一样,将音频文件关联到它,然后打开它。

标签: flutter

解决方案


我已经尝试了很多这样的变体,但没有一个奏效。几天后,我找到并尝试了这个对我有帮助的。

所以,我通过将此代码添加到我的 /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>

推荐阅读