【问题标题】:requestRouteToHost issue under 4.0.3 and 4.0.4 but not otherrequestRouteToHost 问题在 4.0.3 和 4.0.4 下但不是其他
【发布时间】:2013-01-17 09:11:19
【问题描述】:

对于个人项目,我必须检查用于 MMS 的设备 LAN ip 是否可达。 我已经使用提供的 APN 找到了 IP。现在我需要使用requestRouteToHost 方法来检查找到的代理是否有效。

代码在运行 android 2.3 到 4.0 以及从 4.1 到更高版本的设备上完美运行。 但它在 4.0.3 和 4.0.4 下给我一个错误。我已经在多台设备上进行了测试,这不是设备问题,而是版本问题。

if (!connMgr.requestRouteToHost(2, inetAddr)) {
     Log.e(TAG, "unable to request route to host");
     throw new IOException("Cannot establish route to proxy " + inetAddr);
} else {
     Log.e(TAG, "route to host requested");
}

第一个条件始终为真,这是一个真正的问题。

上面的代码包含在我这样制作的 AsynTask 中:

private class AsyncRoute extends AsyncTask<String, Void, Void>
{
    @Override
    protected Void doInBackground(String... proxyAddr)
    {
        try
        {
            ensureRouteToHost(proxyAddr[0]);
            Log.e(TAG, "OK ACK");
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        mInetAck = true;
        return null;
    }
}

找到的 InetAddress 是 -938825536,相当于 192.168.010.200

要启动此 AsyncTask,我使用以下代码:

new AsyncRoute().execute(MMSProxy);
while (!mInetAck);

基本上,它会在执行几个请求之前等待确认。

那么,有人知道是否有绕过这个问题的技巧吗?我的意思是有没有办法做和connMgr.requestRouteToHost(2, inetAddr)一样的事情,可以在每台设备上运行?

谢谢。

Ps:在 Desire S 2.3、Desire S 4.0.3、Xperia lt30p 4.0.4、Nexus S 4.0.3 等上测试。

编辑:在引发异常的设备上,路由 IP 上的 ping 命令有效:

> adb shell ping 192.168.10.200
PING 192.168.10.200 (192.168.10.200) 56(84) bytes of data.
64 bytes from 192.168.10.200: icmp_seq=1 ttl=251 time=4023 ms
64 bytes from 192.168.10.200: icmp_seq=5 ttl=251 time=81.3 ms

但是路由请求失败了:s

【问题讨论】:

    标签: android device android-version


    【解决方案1】:

    问题解决了。 启用 wifi 时找不到到 IP 的路由。最简单的方法是禁用 wifi,做你的事情,然后启用 wifi。

    这是我使用的代码:

    // Disable wifi if it's active
    WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    if (wifiManager.isWifiEnabled())
    {
          mWasWifiActive = true;
          wifiManager.setWifiEnabled(false);
          Log.e(TAG, "Wifi was enabled, now Off.");
    }
    
    // Do stuff here
    
    // Re-enable wifi if it was active before routing
    if (mWasWifiActive)
    {
           WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
           wifiManager.setWifiEnabled(true);
           Log.e(TAG, "Wifi is back online.");
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-05-12
      • 1970-01-01
      • 1970-01-01
      • 2019-12-17
      • 1970-01-01
      • 1970-01-01
      • 2021-12-10
      相关资源
      最近更新 更多