2016-02-05 69 views
0

我正在尝试使用以下链接来下载.XM文件。Android Browser Intent Filter will not Work

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

这里是我的清单片段:

<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> 

下面是我的代码片段未被称为:

@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"); 

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

我已经成功了意图过滤器的相同的代码和类型M3U播放列表等工作

UPDATE:

我想现在接受任何应用程序/八位字节流的链接和我做不到让我的应用程序接收这些链接的意图。我已经尝试了“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> 

回答

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

该URL的文件扩展名是.php

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

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

+0

谢谢。这是否意味着我应该过滤我的应用程序中的所有.php URL,然后在完整的URL中查找.xm? – SparkyNZ

+0

@ SparkyNZ:那么,对于'http'和'https'方案来说,这是可行的。但是,用户可能会感到困惑,试图确定您声称为什么要处理所有PHP页面。不幸的是,您的测试网址不会为此请求提供不同的MIME类型,这基本上意味着您的所有选项都很糟糕。 – CommonsWare

+0

当然,必须有另一种截取.XM文件下载的方法吗?这对于iOS来说非常简单。在iPhone上,我注册了XM文件类型,并且此链接触发了一个openURL方法。我只是想在Android上获得相同的结果。 – SparkyNZ