问题描述
我有一个自定义文件类型/扩展名,我想将其与我的应用相关联.
I have a custom file type/extension that I want to associate my app with.
据我所知,数据元素就是为此目的而制作的,但我无法让它工作.http://developer.android.com/guide/topics/manifest/data-element.html根据文档和很多论坛帖子,它应该是这样工作的:
As far as I know, the data element is made for this purpose, but I can't get it working.http://developer.android.com/guide/topics/manifest/data-element.htmlAccording to the docs, and a lot of forum posts, it should work like this:
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:mimeType="application/pdf" />
</intent-filter>
好吧,它不起作用.我做错了什么?我只是想声明我自己的文件类型.
Well, it does not work. What did I do wrong? I simply want to declare my own file type.
推荐答案
您需要多个意图过滤器来处理您想要处理的不同情况.
You need multiple intent filters to address different situation you want to handle.
示例1,处理没有mimetypes的http请求:
Example 1, handle http requests without mimetypes:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<data android:host="*" />
<data android:pathPattern=".*\.pdf" />
</intent-filter>
处理与后缀无关的 mimetypes:
Handle with mimetypes, where the suffix is irrelevant:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" />
<data android:host="*" />
<data android:mimeType="application/pdf" />
</intent-filter>
处理来自文件浏览器应用的意图:
Handle intent from a file browser app:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
<data android:host="*" />
<data android:pathPattern=".*\.pdf" />
</intent-filter>
这篇关于Android 意图过滤器:将应用程序与文件扩展名关联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!