英文:
Android Intent Filter for custom file type
问题
问题
我有一个zip文件,但带有自定义文件扩展名xyz。
我希望我的应用程序只能打开具有自定义文件扩展名xyz的文件,来自:
- Gmail,
- Android文件浏览器中的“打开方式”,
- Android文件浏览器中的“通过共享”。
我已经尝试过的方法
我尝试过的最佳方法就是只使用mime类型application/zip
。但是这将打开带有文件扩展名**.zip**的文件。
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:mimeType="application/zip" />
</intent-filter>
我尝试添加<data android:pathPattern=".*\\.xyz"/>
。但是这个问题是,只要我不指定android:scheme
和android:host
,它就会被忽略 见此处。
> 只有在为过滤器指定了scheme和host属性时,此属性才有意义。
一旦我像下面的代码段中所见指定了scheme和host,我甚至无法打开任何文件:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:host="*" />
<data android:scheme="*" />
<data android:mimeType="application/zip" />
<data android:pathPattern=".*\\.xyz"/>
</intent-filter>
可能的重复问题:
- Android intent filter: associate app with file extension
- android how to open external file with my application
英文:
Problem
I have a zip file but with a custom file extension xyz.
I want my app to be able to open ONLY files with the custom file extension xyz from:
- Gmail,
Open with
from the android file explorer,Share via
from the android file explorer.
What I have already tried
My best shot was to just use a mime type of application/zip
. However this would also open files with the file extension .zip.
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:mimeType="application/zip" />
</intent-filter>
I tried to add a <data android:pathPattern=".*\\.xyz"/>
. But the problem with this is, that it will be ignored as long as I don't specify android:scheme
and android:host
see here.
> This attribute is meaningful only if the scheme and host attributes are also specified for the filter.
As soon as I specify the scheme and host as seen in the next code segment, I can't even open any file with my App:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:host="*" />
<data android:scheme="*" />
<data android:mimeType="application/zip" />
<data android:pathPattern=".*\\.xyz"/>
</intent-filter>
Possible Duplicates:
答案1
得分: 1
请使用 application/octet-stream
代替 application/zip
。以下代码对我有效:
<intent-filter tools:ignore="AppLinkUrlError"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:priority="50" >
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
<data android:scheme="content" />
<data android:mimeType="application/octet-stream" />
<data android:pathPattern=".*\.ext" />
<data android:pathPattern=".*\..*\.ext" />
<data android:pathPattern=".*\..*\..*\.ext" />
</intent-filter>
英文:
Use application/octet-stream
instead of application/zip
. Bellow works for me:
<intent-filter tools:ignore="AppLinkUrlError"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:priority="50" >
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
<data android:scheme="content" />
<data android:mimeType="application/octet-stream" />
<data android:pathPattern=".*\\.ext" />
<data android:pathPattern=".*\\..*\\.ext" />
<data android:pathPattern=".*\\..*\\..*\\.ext" />
</intent-filter>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论