Explorer中打开自定义文件类型

Explorer中打开自定义文件类型

本文介绍了在Samsung File Explorer中打开自定义文件类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的应用程序可以处理的两种自定义文件类型,我希望能够从各种其他应用程序中打开它们.我为许多人(包括Gmail和设置"文件浏览器)工作的东西,但是还有一些第三种文件管理器(包括Samsung My Files和Astro File Manager)无法识别这些文件类型属于我的应用程序.有没有一种方法可以设计一个意图过滤器,使这些文件浏览器应用程序识别出这些文件应该由我的应用程序打开?

I have two custom filetypes that my app can handle that I would like to be able to open from a wide variety of other apps. What I have is working for many including Gmail and the Settings file explorer, but there several third file managers (including Samsung My Files and Astro File Manager) that do not recognize these filetypes as belonging to my app. Is there a way to craft an intent filter that will enable these file explorer apps to recognize that these files should be opened by my app?

以下是现有的意图过滤器:

Here's the existing intent filters:

<intent-filter>
    <action android:name="android.intent.action.MAIN" />

    <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

<!-- See http://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类型.

I now have a solution that works for several common file managers including Samsung's. What you need is one filter that specifies a MIME type, and a separate filter that does not specify a MIME type and filters based on file extension. I added one more that uses a wildcard MIME type and filters based on file extension since at least one file manager seemed to specifying an empty MIME type.

关于元素在过滤器中的确切工作方式的讨论值得多次仔细阅读: https://developer.android.com/guide/components/intents-filters#DataTest

The discussion of exactly how elements work in the filter is worth reading carefully several times: 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的文件.参见此答案,详细了解为什么以及如何克服它.

The solution above will fail to match a file that has a b in the path before bloomd. See this answer for details on why and how to overcome that.

这篇关于在Samsung File Explorer中打开自定义文件类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 14:19