2

I'm facing a problem when using a S31 Cat phone with Android 7.1.2. But i'm not sure this problem is related to this phone or simply Android 7 I've tried this on Sony Xperia and others Samsung phones.

I'm currently developping an app that creates an access point with reflection methods (with or without this library :Wifi Ap Control). After creating the access Point another device is connecting to the Access Point and initiating TCP Server. My App try to create a Socket to this server.

Here is how i'm creating the Access Point:

    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();
    }

and Here is how i'm simply creating the 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;
    }

When i'm trying to create and connect the socket, two different things happen : When i'm manually starting the Access Point, i get an exceptions when the device is not connected, but that's fine, because I ca connect to it when it's connected to the access point.

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

or

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

But when i'm doing it with reflection, i'm getting another type of exception. And i cannot connect to the device even if it's actually connected to the access point !

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

I'm starting to guess that when doing this reflecion method, Android can't find default Network methods to bind the socket.

Do you have any idea regarding this problem ?

Chimimoryo
  • 21
  • 3

0 Answers0