我的应用指定能够在 list 文件中打开我自己的文件扩展名,如下所示:
<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"/>
<data android:host="*"/>
<data android:mimeType="*/*"/>
<data android:pathPattern=".*\\.ext" />
<data android:pathPattern=".*\\..*\\.ext" />
<data android:pathPattern=".*\\..*\\..*\\.ext" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.ext" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.ext" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\.ext" />
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\..*\\..*\\.ext" />
这曾经在标准的 Android 文件浏览器(“我的文件”)上运行良好,并且仍然可以在运行 Android 4.3 的旧测试设备上运行,但在我运行 Android 6 和 8 的其他设备上不起作用。它也适用于带有其他文件浏览器的新设备(尽管不是全部)。
我也尝试过使用相应的 mime 类型的 png 和 pdf,但它不会在能够打开这些文件的应用程序列表中显示我的应用程序。
标准 Android 文件浏览器需要什么才能识别我的应用,以便能够打开带有我的扩展名的文件?
编辑:我也试过
<data android:scheme="content"/>
最佳答案
试试这个(将“自定义”更改为您要使用的扩展名):
<activity android:name=".MainActivity">
<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"/>
<data android:mimeType="*/*"/>
<data android:pathPattern=".*\\.custom"/>
<!-- These additional pathPattern blocks are to allow for paths with
additional periods in them. See:
http://stackoverflow.com/questions/3400072/pathpattern-to-match-file-extension-does-not-work-if-a-period-exists-elsewhere-i/8599921 -->
<data android:pathPattern=".*\\..*\\.custom"/>
<data android:pathPattern=".*\\..*\\..*\\.custom"/>
<data android:pathPattern=".*\\..*\\..*\\..*\\.custom"/>
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.custom"/>
<data android:host="*"/>
</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"/>
<data android:pathPattern=".*\\.custom"/>
<data android:pathPattern=".*\\..*\\.custom"/>
<data android:pathPattern=".*\\..*\\..*\\.custom"/>
<data android:pathPattern=".*\\..*\\..*\\..*\\.custom"/>
<data android:pathPattern=".*\\..*\\..*\\..*\\..*\\.custom"/>
<data android:host="*"/>
</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:mimeType="application/vnd.ni.custom" android:scheme="file"/>
</intent-filter>
</activity>
关于Android 自定义文件扩展名 Intent 不适用于标准文件浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53110192/