2013-05-04 89 views
0

当我使用自定义方案(例如myhttp)时,一切正常,但是如果我使用http,它不会处理,并且每次浏览器打开主机时(例如:192.168。 1.111)。在Android中处理http协议的自定义url

我怎样才能解决这个问题?

我的manifest.xml

 <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="192.168.1.111"/> 
     </intent-filter> 

我的活动:

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    final Intent intent = getIntent(); 
    Log.i("MyTAG", "here--01"); 
} 

回答

1

给你的意图过滤比默认浏览器的更高的优先级:

http://developer.android.com/guide/topics/manifest/intent-filter-element.html#priority

<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="192.168.1.111"/> 
     <android:priority="999"/> 
    </intent-filter> 

它控制接收广播消息的广播接收器的执行顺序为 。那些具有较高优先级值的是 之前调用较低值。 (此命令仅适用于 同步消息;对于异步消息,它将被忽略。)

该值必须是整数,例如“100”。较高的数字具有较高的优先级 。默认值为0值必须大于 比-1000和小于1000


此外,如果你正在处理您的浏览器。您曾经一度将Chrome设置为默认应用来打开此意图。所以你不得不重置这个。

转到Settings > Apps > Chrome (or Firefox or w/e) > Clear defaults

clear defaults


您可以使用名为Default App Manager一个应用程序来检查什么的默认值已设置

+0

感谢答复,但不幸的是它具有相同的结果。我试过了,Chrome和Firefox。 – chrome 2013-05-04 10:34:33

+0

@chrome更新了我的答案 – Blundell 2013-05-04 11:37:39

+0

我查看了设置,但没有默认设置,因此它的按钮被禁用。您的评论后,当我长时间按我的自定义网址。其次,浏览器建议我使用MyApp打开。 – chrome 2013-05-04 11:46:56