问题描述
我有一个自定义的文件类型/扩展名,我想我的应用程序有关联。
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,处理HTTP请求,而不MIME类型:
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>
手柄与MIME类型,其中后缀是无关紧要的:
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的意图过滤器:与文件扩展名相关联的应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!