我有一个自定义文件类型/扩展名,我想要将我的应用程序与其关联。
据我所知,数据元素就是为了这个目的而创建的,但是我不能让它工作。http://developer.android.com/guide/topics/manifest/data-element.html根据文档和许多论坛的帖子,它应该是这样工作的:
<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>
好吧,它不起作用。我做错什么了?我只想声明我自己的文件类型。
发布于 2011-02-24 06:00:35
您需要多个意图过滤器来处理您想要处理的不同情况。
示例1,处理不带mimetype的http请求:
<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>
处理mimetype,其中后缀是不相关的:
<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>
处理来自文件浏览器应用程序的意图:
<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>
发布于 2012-10-16 20:59:42
其他的解决方案对我来说并不可靠,直到我添加了:
android:mimeType="*/*"
在此之前,它在一些应用程序中工作,在一些应用程序中不起作用。
为我提供完整的解决方案:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" android:host="*" android:pathPattern=".*\\.EXT" android:mimeType="*/*" />
</intent-filter>
发布于 2012-08-28 13:44:18
The pathPattern
<data android:pathPattern=".*\\.pdf" />
如果文件路径在".pdf“前包含一个或多个点,则不起作用。
这将会起作用:
<data android:pathPattern=".*\\.pdf" />
<data android:pathPattern=".*\\..*\\.pdf" />
<data android:pathPattern=".*\\..*\\..*\\.pdf" />
<data android:pathPattern=".*\\..*\\..*\\..*\\.pdf" />
如果你想支持更多的点,可以添加更多的点。
https://stackoverflow.com/questions/3760276
复制相似问题