
我有两个自定义文件类型,我的应用程序可以处理,我希望能够从各种其他应用程序打开.我所拥有的功能包括Gmail和设置文件浏览器,但有几个第三个文件管理器(包括三星我的文件和Astro文件管理器)无法识别这些文件类型属于我的应用程序.有没有办法制作一个意图过滤器,使这些文件浏览器应用程序能够识别这些文件应该由我的应用程序打开?
这是现有的意图过滤器:
<intent-filter> <action androID:name="androID.intent.action.MAIN" /> <category androID:name="androID.intent.category.LAUNCHER" /></intent-filter><!-- See https://stackoverflow.com/questions/1733195/androID-intent-filter-for-a-particular-file-extension/2062112#2062112 --><!-- Capture content by MIME type, which is how Gmail broadcasts attachment open requests. pathPattern and file extensions are ignored, so the MIME type *MUST* be explicit, otherwise we will match absolutely every file opened.--><intent-filter androID:icon="@drawable/book" androID:label="@string/app_name" androID:priority="50"> <action androID:name="androID.intent.action.VIEW" /> <category androID:name="androID.intent.category.broWSABLE" /> <category androID:name="androID.intent.category.DEFAulT" /> <!-- needed for properly formatted email messages --> <data androID:mimeType="application/vnd.bloom" androID:scheme="content" /> <!-- needed for mangled email messages --> <data androID:mimeType="application/bloom" androID:scheme="content" /> <!-- needed for properly formatted email messages --> <data androID:mimeType="application/vnd.bloomd" androID:scheme="content" /> <!-- needed for mangled email messages --> <data androID:mimeType="application/bloomd" androID:scheme="content" /> <!-- needed for properly formatted email messages --> <data androID:mimeType="application/vnd.bloombundle" androID:scheme="content" /> <!-- needed for mangled email messages --> <data androID:mimeType="application/bloombundle" androID:scheme="content" /> <!-- needed for mangled email messages --> <data androID:mimeType="application/octet-stream" androID:scheme="content" /></intent-filter><!-- Capture file open requests (pathPattern is honoured) where no MIME type is provIDed in the Intent. An Intent with a null MIME type will never be matched by a filter with a set MIME type, so we need a second intent-filter if we wish to also match files with this extension and a non-null MIME type (even if it is non-null but zero length).--><intent-filter androID:icon="@drawable/book" androID:label="@string/app_name" androID:priority="50"> <action androID:name="androID.intent.action.VIEW" /> <category androID:name="androID.intent.category.broWSABLE" /> <category androID:name="androID.intent.category.DEFAulT" /> <data androID:scheme="file" /> <data androID:host="*" /> <!-- Work around AndroID's ugly primitive PatternMatcher implementation that can't cope with finding a . early in the path unless it's explicitly matched. --> <data androID:pathPattern=".*\.bloomd" /> <data androID:pathPattern=".*\..*\.bloomd" /> <data androID:pathPattern=".*\..*\..*\.bloomd" /> <data androID:pathPattern=".*\..*\..*\..*\.bloomd" /> <data androID:pathPattern=".*\..*\..*\..*\..*\.bloomd" /> <data androID:pathPattern=".*\..*\..*\..*\..*\..*\.bloomd" /> <data androID:pathPattern=".*\..*\..*\..*\..*\..*\..*\.bloomd" /> <data androID:pathPattern=".*\.bloombundle" /> <data androID:pathPattern=".*\..*\.bloombundle" /> <data androID:pathPattern=".*\..*\..*\.bloombundle" /> <data androID:pathPattern=".*\..*\..*\..*\.bloombundle" /> <data androID:pathPattern=".*\..*\..*\..*\..*\.bloombundle" /> <data androID:pathPattern=".*\..*\..*\..*\..*\..*\.bloombundle" /> <data androID:pathPattern=".*\..*\..*\..*\..*\..*\..*\.bloombundle" /></intent-filter><!-- Capture file open requests (pathPattern is honoured) where a (possibly blank) MIME type is provIDed in the Intent. This filter may only be necessary for supporting ES file Explorer, which has the probably BUGgy behavIoUr of using an Intent with a MIME type that is set but zero-length. It's impossible to match such a type except by using a global wildcard.--><intent-filter androID:icon="@drawable/book" androID:label="@string/app_name" androID:priority="50"> <action androID:name="androID.intent.action.VIEW" /> <category androID:name="androID.intent.category.broWSABLE" /> <category androID:name="androID.intent.category.DEFAulT" /> <data androID:scheme="file" /> <data androID:host="*" /> <data androID:mimeType="*/*" /> <!-- Work around AndroID's ugly primitive PatternMatcher implementation that can't cope with finding a . early in the path unless it's explicitly matched. --> <data androID:pathPattern=".*\.bloomd" /> <data androID:pathPattern=".*\..*\.bloomd" /> <data androID:pathPattern=".*\..*\..*\.bloomd" /> <data androID:pathPattern=".*\..*\..*\..*\.bloomd" /> <data androID:pathPattern=".*\..*\..*\..*\..*\.bloomd" /> <data androID:pathPattern=".*\..*\..*\..*\..*\..*\.bloomd" /> <data androID:pathPattern=".*\..*\..*\..*\..*\..*\..*\.bloomd" /> <data androID:pathPattern=".*\.bloombundle" /> <data androID:pathPattern=".*\..*\.bloombundle" /> <data androID:pathPattern=".*\..*\..*\.bloombundle" /> <data androID:pathPattern=".*\..*\..*\..*\.bloombundle" /> <data androID:pathPattern=".*\..*\..*\..*\..*\.bloombundle" /> <data androID:pathPattern=".*\..*\..*\..*\..*\..*\.bloombundle" /> <data androID:pathPattern=".*\..*\..*\..*\..*\..*\..*\.bloombundle" /></intent-filter>解决方法:
我现在有一个适用于包括三星在内的几个常见文件管理器的解决方案.您需要的是一个指定MIME类型的过滤器,以及一个不指定MIME类型的单独过滤器和基于文件扩展名的过滤器.我添加了一个使用通配符MIME类型和基于文件扩展名的过滤器,因为至少有一个文件管理器似乎指定了一个空的MIME类型.
关于过滤器中元素如何工作的讨论值得仔细阅读几次:https://developer.android.com/guide/components/intents-filters#DataTest
解:
<!-- Matches intents by MIME type --> <intent-filter androID:icon="@drawable/book" androID:label="@string/app_name"> <action androID:name="androID.intent.action.VIEW" /> <category androID:name="androID.intent.category.broWSABLE" /> <category androID:name="androID.intent.category.DEFAulT" /> <data androID:scheme="content" /> <data androID:scheme="file" /> <data androID:mimeType="application/vnd.bloom" /> <data androID:mimeType="application/bloom" /> <data androID:mimeType="application/vnd.bloomd" /> <data androID:mimeType="application/bloomd" /> <data androID:mimeType="application/vnd.bloombundle" /> <data androID:mimeType="application/bloombundle" /> <data androID:mimeType="application/octet-stream" /> </intent-filter> <!-- Matches intents by file extension --> <intent-filter androID:icon="@drawable/book" androID:label="@string/app_name"> <action androID:name="androID.intent.action.VIEW" /> <action androID:name="androID.intent.action.SEND" /> <category androID:name="androID.intent.category.broWSABLE" /> <category androID:name="androID.intent.category.DEFAulT" /> <data androID:scheme="content" /> <data androID:scheme="file" /> <data androID:host="*" /> <data androID:pathPattern=".*bloomd" /> <data androID:pathPattern=".*bloombundle" /> </intent-filter> <!-- Matches intents by file extension when an empty MIME type is set --> <intent-filter androID:icon="@drawable/book" androID:label="@string/app_name"> <action androID:name="androID.intent.action.VIEW" /> <action androID:name="androID.intent.action.SEND" /> <category androID:name="androID.intent.category.broWSABLE" /> <category androID:name="androID.intent.category.DEFAulT" /> <data androID:mimeType="*/*" /> <data androID:scheme="content" /> <data androID:scheme="file" /> <data androID:host="*" /> <data androID:pathPattern=".*bloomd" /> <data androID:pathPattern=".*bloombundle" /> </intent-filter>编辑:
上面的解决方案将无法匹配bloomd之前路径中具有b的文件.有关为何以及如何克服这些问题的详细信息,请参见this answer.
总结以上是内存溢出为你收集整理的android – 在Samsung文件资源管理器中打开自定义文件类型全部内容,希望文章能够帮你解决android – 在Samsung文件资源管理器中打开自定义文件类型所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)