【问题标题】:Android Browser Intent Filter Won't WorkAndroid 浏览器意图过滤器不起作用
【发布时间】:2016-02-05 00:31:17
【问题描述】:

我正在尝试使用以下链接下载 .XM 文件。

http://api.modarchive.org/downloads.php?moduleid=50479#ngs_cvrg.xm

这是我清单中的一个 sn-p:

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

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
                        <intent-filter>
                          <action android:name="android.intent.action.VIEW" />
                          <action android:name="android.intent.action.EDIT" />
                          <category android:name="android.intent.category.DEFAULT" />
                        <data android:mimeType="application/octet-stream" />
                        <data android:host="*" />
              <data android:pathPattern=".*\\.xm" />
                        </intent-filter>
                        <intent-filter>
                          <action android:name="android.intent.action.VIEW" />
                          <action android:name="android.intent.action.EDIT" />
                          <category android:name="android.intent.category.DEFAULT" />
                          <data android:mimeType="application/mytestapp" />
                          <data android:host="*" /> 
              <data android:pathPattern=".*\\.xm" />
                        </intent-filter>            
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:scheme="file" />
                <data android:pathPattern=".*\\.xm" />
                <data android:host="*" />
                <data android:mimeType="text/plain"/>
            </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="http" />
                        <data android:mimeType="*/*" />
                        <data android:pathPattern=".*\\.xm" />
                        <data android:host="*" />
                    </intent-filter>            
                    </activity>

下面是我没有被调用的代码的 sn-p:

  @Override
  protected void onCreate( Bundle savedInstanceState )
  {
    CheckForBrowserActivation();
  }


  public void CheckForBrowserActivation()
  {
    Intent intent = getIntent();
    String sData  = intent.getDataString();
    ContextActivity.LogDebugf( "Intent [%s] Data[%s]\n", intent.getAction(), sData );

    if( Intent.ACTION_VIEW.equals( intent.getAction() ) )
    {
      ContextActivity.LogDebugf( "BROWSER, ACTION_VIEW\n" );

有人可以告诉我为什么 Intent 过滤器不适用于此链接吗?

我已经成功地将相同的代码和类型的意图过滤器用于 m3u 播放列表等。

更新:

我现在正在尝试接收任何应用程序/八位字节流链接,但我无法让我的应用程序通过该链接接收这些意图。我已经尝试过“http”和“file”两种方案,但都不起作用。我已经删除了所有意图过滤器,所以我现在只有一个(见下文)。为什么这不起作用?

<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="http" />
  <data android:host="*" />              
  <data android:mimeType="application/octet-stream" />
</intent-filter>

【问题讨论】:

    标签: android android-intent intentfilter openurl


    【解决方案1】:
    http://api.modarchive.org/downloads.php?moduleid=50479#ngs_cvrg.xm
    

    此网址的文件扩展名是.php

    <data android:pathPattern=".*\\.xm" />
    

    这个pathPattern 的文件扩展名是.xm。这与您的网址不匹配。

    【讨论】:

    • 谢谢。这是否意味着我应该在我的应用程序中过滤所有 .php URL,然后在完整 URL 中查找 .xm?
    • @SparkyNZ:嗯,这将适用于httphttps 方案。但是,用户可能会感到困惑,试图确定您声称处理所有 PHP 页面的原因。不幸的是,您的测试 URL 没有为此请求提供不同的 MIME 类型,这基本上意味着您的所有选项都很糟糕。
    • 肯定有其他方法可以拦截 .XM 文件的下载?这在 iOS 上真的很容易做到。在 iPhone 上,我注册了 XM 文件类型,这个链接触发了一个 openURL 方法。我只想在 Android 上达到同样的效果。
    • @SparkyNZ:Android 专注于 MIME 类型。如果您的内容具有不同的 MIME 类型,并且服务器使用该 MIME 类型为其提供服务,则支持该 MIME 类型很容易。
    • @SparkyNZ:我使用 curl 转储了 HTTP 标头。它返回application/octet-stream, IIRC,它是一种 MIME 类型,但不是 distinct MIME 类型。 application/octet-stream 是 MIME 类型的 ¯\_(ツ)_/¯。 “也许您还可以建议一个也返回 MIME 类型的示例链接?” -- 我希望这个网页的 URL 返回text/html
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-23
    • 2015-04-11
    • 2012-06-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多