你能解释一下requestRouteToHost()的机器人的功能? [英] Can you explain the Functionality of requestRouteToHost() in android?

查看:371
本文介绍了你能解释一下requestRouteToHost()的机器人的功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的code我使用 requestRouteToHost()方法:

这是否路由意味着改变WIFI到3G,反之亦然??

我的code不工作...

 公共静态布尔isHostAvailable(上下文的背景下,字符串urlString)抛出的UnknownHostException,MalformedURLException的{
     布尔RET = FALSE;
     INT NETWORKTYPE = ConnectivityManager.TYPE_WIFI;
     ConnectivityManager厘米=(ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
     如果(厘米!= NULL){
             的NetworkInfo NF = cm.getActiveNetworkInfo();
             如果(NF!= NULL){
                     NETWORKTYPE = nf.getType();
             }
             网址URL =新的URL(urlString);
             InetAddress类iAddress = InetAddress.getByName(url.getHost());
             RET = cm.requestRouteToHost(NETWORKTYPE,ipToInt(iAddress.getHostAddress()));
     }
     返回RET;
}

公共静态INT ipToInt(字符串地址){
     的String [] addrArray = addr.split(\\);

     INT NUM = 0;
     的for(int i = 0; I< addrArray.length;我++){
         INT功率= 3-I;

         NUM + =((的Integer.parseInt(addrArray [I])%256 * Math.pow(256,功率)));
     }
     返回NUM;
 }
 

感谢

解决方案

方法 requestRouteToHost()不改变的WiFi到3G,反之亦然!

<一个href="http://developer.android.com/reference/android/net/ConnectivityManager.html#requestRouteToHost%28int,%20int%29"相对=nofollow>官方文档

 公共布尔requestRouteToHost(INT NETWORKTYPE,INT hostAddress)
 

  

确保将网络路由存在通​​过指定的网络接口,提供流量到指定的主机。添加已经存在被忽略,但治疗的途径的尝试是成功的。

  • 参数

    NETWORKTYPE 网​​络的类型在哪些流量到指定的主机进行路由

    hostAddress 的主机的IP地址,该路由所期望的

  • 返回

    成功真的假失败

In my code I am using requestRouteToHost() method:

Does this routing means changing the WIFI to 3G or vice versa??

My code is not working...

public static boolean isHostAvailable(Context context, String urlString) throws UnknownHostException, MalformedURLException { 
     boolean ret = false; 
     int networkType = ConnectivityManager.TYPE_WIFI; 
     ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); 
     if(cm != null){ 
             NetworkInfo nf = cm.getActiveNetworkInfo(); 
             if(nf != null){ 
                     networkType = nf.getType(); 
             } 
             URL url = new URL(urlString); 
             InetAddress  iAddress = InetAddress.getByName(url.getHost()); 
             ret = cm.requestRouteToHost(networkType, ipToInt(iAddress.getHostAddress())); 
     } 
     return ret; 
}

public static int ipToInt(String addr) {
     String[] addrArray = addr.split("\\.");

     int num = 0;
     for (int i=0;i<addrArray.length;i++) {
         int power = 3-i;

         num += ((Integer.parseInt(addrArray[i])%256 * Math.pow(256,power)));
     }
     return num;
 }

Thanks

解决方案

Method requestRouteToHost() does not change wifi to 3G or vice versa!

Official Documentation :

public boolean requestRouteToHost (int networkType, int hostAddress) 

Ensure that a network route exists to deliver traffic to the specified host via the specified network interface. An attempt to add a route that already exists is ignored, but treated as successful.

  • Parameters

    networkType the type of the network over which traffic to the specified host is to be routed

    hostAddress the IP address of the host to which the route is desired

  • Returns

    true on success, false on failure

这篇关于你能解释一下requestRouteToHost()的机器人的功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆