【问题标题】:Custom extension file not opening in my app自定义扩展文件未在我的应用程序中打开
【发布时间】:2014-05-13 10:45:12
【问题描述】:

我希望通过我的应用打开自定义扩展文件 (*.xyz)。在应用程序清单文件中,我正在编写以下内容:

<intent-filter>
    <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT"/>
        <data android:scheme="http"    android:host="*" android:pathPattern=".*\\.xyz" />
        <data android:scheme="https"   android:host="*" android:pathPattern=".*\\.xyz" />
        <data android:scheme="content" android:host="*" android:pathPattern=".*\\.xyz" />
         <data android:scheme="file"   android:host="*" android:pathPattern=".*\\.xyz" />
</intent-filter>

之后,我将在设备上安装我的应用程序,并发送一封包含Sample.xyz 邮件作为附件的邮件。当我尝试在邮件客户端中点击附件以打开附件时,它会给出一个名为

的错误

No app can open this attachment for viewing

即使我下载附件然后尝试打开它也会报错

Can't open file

谁能建议可能出了什么问题?

【问题讨论】:

  • 尝试先添加另一个类别:
  • 你可以试试这个:&lt;data android:scheme="content" android:host="*" android:mimeType="application/xyz" /&gt;
  • @ManishMulimani android:mimeType="application/xyz" 是做什么的?

标签: android android-intent intentfilter file-type


【解决方案1】:

您的过滤器不匹配,因为它不是 http https 文件和内容 - 为此您需要不同的 &lt;intent-filter&gt; - 看看这里: https://github.com/ligi/PassAndroid/blob/master/src/main/AndroidManifest.xml 就像我为 *.pkpass 为 *.xyz 做的一样:

    <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:host="*"
            android:pathPattern=".*\\.xyz"
            android:scheme="http" />
    </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:host="*"
            android:pathPattern=".*\\.xyz"
            android:scheme="https" />
    </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:host="*"
            android:pathPattern=".*\\.xyz"
            android:scheme="file" />
    </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:host="*"
            android:pathPattern=".*\\.xyz"
            android:scheme="content" />
    </intent-filter>

【讨论】:

  • 我已经按照您所指出的方式添加了意图过滤器,而且我还添加了您的答案中缺少的 mimeType。我的 logcat 'resolveIntent failed: found match, but none with CATEGORY_DEFAULT Unable to find support activity 中仍然出现以下错误。 mime-type: application/xyz, uri: content://com.google.android.email.attachmentprovider/4/941/RAW, 标准化 mime-type: application/xyz 标准化 uri: content://com.google.android .email.attachmentprovider/4/941/RAW resolveIntent 失败:找到匹配项,但没有 CATEGORY_DEFAULT `
  • 我在这个例子中没有做 mime-type,因为你在原来的问题中没有这样做 - 认为你的用例没有特定的 mime-type。这段代码适用于我和很多用户——你能说明你是如何适应它的吗?当您单击例如时,您是否收到该消息?在邮件附件上?
  • 是的,当我点击邮件附件时收到此消息
  • 点击浏览器中的链接是否也会失败?请出示您的清单! PS:Intent-Intercept 是调试此类问题的好工具。
猜你喜欢
  • 1970-01-01
  • 2014-05-14
  • 1970-01-01
  • 1970-01-01
  • 2016-01-20
  • 2022-01-17
  • 2019-12-11
  • 2019-08-28
  • 1970-01-01
相关资源
最近更新 更多