Android接入点默认网络

时间:2018-03-09 08:31:54

标签: android access-point

我在Android 7.1.2中使用S31 Cat phone时遇到问题。但我不确定这个问题与这款手机或Android 7有关 我在索尼Xperia和其他三星手机上试过这个。

我目前正在开发一个使用反射方法创建访问点的应用程序(有或没有此库:Wifi Ap Control)。 创建访问点后,另一台设备正在连接到访问点并启动TCP服务器。我的应用尝试为此服务器创建一个Socket。

以下是我创建接入点的方式:

    WifiConfiguration myConfig = new WifiConfiguration();
    myConfig.SSID = ssid; // SSID name of netwok
    myConfig.preSharedKey = password; // password for network
    myConfig.allowedKeyManagement.set(4); // 4 is for KeyMgmt.WPA2_PSK which is not exposed by android KeyMgmt class
    myConfig.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN); // Set Auth Algorithms to open
    try {
        Method method = mWifiManager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class, boolean.class);
        return (Boolean) method.invoke(mWifiManager, myConfig, true);  // setting and turing on android wifiap with new configrations
    } catch (Exception e) {
        e.printStackTrace();
    }

以下是我如何创建Socket:

   try {
        socketTcp = new Socket();
        socketTcp.connect(new InetSocketAddress(address, port), SOCKET_CONNECTION_TIMEOUT);
        receiveStream = socketTcp.getInputStream();
        sendStream = socketTcp.getOutputStream();
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }

当我尝试创建并连接套接字时,会发生两种不同的事情: 当我手动启动接入点时,我在设备未连接时会出现异常,但这很好,因为当它连接到接入点时我可以连接到它。 / p>

03-09 09:00:41.336 22049-22081/eu.test.socket W/System.err: java.net.NoRouteToHostException: No route to host

03-09 09:00:43.342 22049-22081/eu.test.socket W/System.err: java.net.SocketTimeoutException: connect timed out

但是当我用反射做这件事时,我得到另一种类型的例外。即使它实际连接到接入点,我也无法连接到设备!

03-09 08:55:41.086 21265-21300/eu.test.socket W/System.err: java.net.ConnectException: Network is unreachable

我开始猜测在执行此反思方法时,Android无法找到绑定套接字的默认网络方法。

你对这个问题有什么看法吗?

0 个答案:

没有答案