【问题标题】:intent filter link my app to all files意图过滤器将我的应用链接到所有文件
【发布时间】:2014-06-18 07:56:46
【问题描述】:

我有一个扩展名为 .myext 的自定义文件类型。 我已经阅读了 android 文档和许多 SO 帖子,以了解如何配置意图过滤器以将这些文件关联到我的应用程序。它可以工作,但不能正常工作。

当我使用这个意图过滤器时:

        <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/*" />
            <data android:pathPattern=".*\\.myext" />
            <data android:host="*" />
        </intent-filter>

然后它将.myext 文件链接到我的应用程序,但也链接到没有应用程序关联的每个文件。所以我可以打开我不想要的.otherext 文件。

然后我发现这个答案https://stackoverflow.com/a/5097734/575481 建议有多个意图过滤器,所以我得到:

        <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=".*\\.myext" />
        </intent-filter>
        <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/*" />
        </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=".*\\.myext" />
        </intent-filter>

但这似乎对我不起作用。

我想要的是:我的应用只打开 .myext 文件。你有什么想法吗?

此外,我需要打开一些其他文件 ext (.myext1, .myext2) ,但我想一旦我获得了正确的意图过滤器,我只需将其复制给其他带有扩展名的文件,对吗?

【问题讨论】:

    标签: android intentfilter


    【解决方案1】:

    我明白了。就我而言,我试图从电子邮件中获取 .ppp 并且它正在获取任何文件。 这是工作过滤器

        <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="content"   android:pathPattern=".*\\.ppp" android:mimeType="application/ppp"/>
            </intent-filter>
    

    在您的活动的 onCreate 上放置一个断点并检查其中的值

        getIntent()
    

    具体来说,mData 应该为您提供为 android:scheme 编写的内容和 mType 为 android.mimeType 编写的内容

    【讨论】:

      猜你喜欢
      • 2015-10-23
      • 2016-09-29
      • 2015-05-01
      • 2013-10-03
      • 2016-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-14
      相关资源
      最近更新 更多