在Android中处理http协议的自定义URL

时间:2013-05-04 09:45:50

标签: android android-intent

当我使用自定义方案(例如myhttp)时,一切都按预期工作,但是如果我使用http,它就无法处理,并且每次浏览器打开主机时(例如:192.168.1.111)。

我该如何解决这个问题?

我的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 个答案:

答案 0 :(得分: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的应用来检查您设置的默认值