Android的意图过滤器,自定义的文件扩展名 [英] android intent filter for custom file extension

查看:166
本文介绍了Android的意图过滤器,自定义的文件扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让一个Android应用程序打开文件扩展名.abc的,这是从Android清单XML我的应用程序部分。

I am trying to make an android app to open files with extension .abc and this is my application section from android manifest xml

<application android:label="@string/app_name" android:icon="@drawable/icon">
    <activity android:name="com.example.app.ActName" android:label="AppName">
        <intent-filter>
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <category android:name="android.intent.category.BROWSABLE"/>
            <data android:mimeType="image/jpeg"/>
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="file" />
            <data android:mimeType="*/*" />
            <data android:pathPattern=".*\\.abc" />
            <data android:host="*" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
</application>

我用所有的经验,最流行和最相关的问题

I used all the experience from the most popular and related questions

<一个href="http://stackoverflow.com/questions/1733195/android-intent-filter-for-a-particular-file-extension">Android意图过滤特定文件扩展名?

<一个href="http://stackoverflow.com/questions/3760276/android-intent-filter-associate-app-with-file-extension">Android意图过滤器,文件扩展助理应用程序

<一个href="http://stackoverflow.com/questions/9518318/android-how-to-create-intent-filter-for-custom-file-extension-that-does-not-make">Android如何创建意图过滤器进行自定义的文件扩展名,不使它成为一个选择器的一切在手机上部分

而在最后,这并不工作 - 当我在名为ES文件浏览器name.abc它要求我的文件点击,如果我要打开的文件为文本或图像等时,它实际上应该只在我的应用程序打开文件,而不是

And in the end this does not work - when I click on a file named "name.abc" in ES file browser it asks me if i want to open the file as text or image etc. when it actually supposed to just open the file in my app instead

它看起来像不同的Andr​​oid系统和不同的文件浏览器中的行为不同的方式 - 一个意图过滤器的工作原理只是罚款4.2ES文件浏览器,并在默认文件管理器4.0.4,但不会在所有的工作在4.2和4.0.4中的总指挥官,并在ES文件浏览器4.0.4

it looks like different android systems and different file browsers act in different way - one intent filter works just fine on 4.2 in "ES File Explorer" and on 4.0.4 in default file manager, but does not work at all on 4.2 and 4.0.4 in "Total Commander" and on 4.0.4 in "ES File Explorer"

推荐答案

首先,第一个意图过滤器在你的例子使用MIME类型为image / jpeg 。为 JPEG .abc的扩展?

First of all, the first intent-filter in your example uses MIME type image/jpeg. Is jpeg your .abc extension?

我想可能有三个原因,这不起作用:

I think there may be three reasons why this does not work:

  1. 您需要添加更多的MIME类型。尝试添加以下内容:

  1. You need to add more MIME types. Try adding the following:

<intent-filter>
    <action android:name="android.intent.action.VIEW"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <category android:name="android.intent.category.BROWSABLE"/>
    <data android:mimeType="application/abc"/>
</intent-filter>

<intent-filter>
    <action android:name="android.intent.action.VIEW"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <category android:name="android.intent.category.BROWSABLE"/>
    <data android:mimeType="application/octet-stream"/>
</intent-filter>

和,如果你的 .abc的格式文本格式:

And, if your .abc format is a text format:

<intent-filter>
    <action android:name="android.intent.action.VIEW"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <category android:name="android.intent.category.BROWSABLE"/>
    <data android:mimeType="text/plain"/>
</intent-filter>

  • 您已经注册了文件方案。您可能还需要在内容方案:

  • You have registered the file scheme. You might also need the content scheme:

    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="content" />
        <data android:mimeType="*/*" />
        <data android:pathPattern=".*\\.abc" />
        <data android:host="*" />
    </intent-filter>
    

  • 传言有它 pathPattern 以一个点只匹配包含单个点的文件。在你的榜样,这将意味着你的应用程序将与 One.abc 而与 Two.Dots.abc 。尝试增加pathPatterns 。* \\。* \\。ABC 。* \\ .. \\ *。* \\。 ABC 等:

  • Rumor has it that pathPattern with a dot only matches files containing a single dot. In your example, this would mean that your app would be associated with One.abc but not with Two.Dots.abc. Try adding more pathPatterns .*\\..*\\.abc, .*\\..*\\..*\\.abc etc.:

    <intent-filter>
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="file" />
        <data android:mimeType="*/*" />
        <data android:pathPattern=".*\\..*\\.abc" />
        <data android:host="*" />
    </intent-filter>
    

  • 这篇关于Android的意图过滤器,自定义的文件扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆