Android中的自定义文件扩展名

时间:2014-12-18 13:36:45

标签: android android-manifest intentfilter file-extension

我有一个像.foo这样的自定义文件扩展名,我想将我的应用与之关联起来。我创建了这个Intent-Filter:

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

问题是这在某些设备上不起作用。例如,以下仅适用于Samsung Galaxy S3(Android版本:4.4.2):

<data android:scheme="file" android:mimeType="*/*"  android:pathPattern=".*\\.foo" android:host="*"/>

然而,对于LG G2(Android版本:4.4.2),只有这一行有效:

<data android:scheme="file" android:pathPattern=".*\\.foo"/>

更糟糕的是,Nexus 7(Android版本:5.0)似乎根本无法识别自定义文件结尾。

有没有人遇到类似的问题,并且知道解决方案?

2 个答案:

答案 0 :(得分:0)

文件模式很棘手......似乎是由开发人员专门完成的。 看起来文件模式在不同设备上的工作方式不同,但它只取决于文件结构的深度。请看这个链接:pathPattern to match file extension does not work if a period exists elsewhere in the file name?

答案 1 :(得分:0)

我认为这种方式对我有用(用您要使用的扩展名更改“自定义”):

version from 4 to 3 in every metadata file in node_modules/@ionic-native