1

Trying to get an access point set up on Android 7.1 using setWifiApEnableMethod with all required permissions granted,

  public static boolean createWAP(final WifiManager wifiManager, String apName) {
        final WifiConfiguration netConfig = new WifiConfiguration();
        netConfig.SSID = apName;
        netConfig.hiddenSSID = false;
        netConfig.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
        netConfig.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
        netConfig.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
        netConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
        try {
            final Method setWifiApMethod = wifiManager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class, boolean.class);
            boolean apstatus = (Boolean) setWifiApMethod.invoke(wifiManager, null, true);
            Log.d(TAG, "WAP created: " + apstatus);
            return apstatus;
        } catch (Exception e) {
            Log.d(TAG, "WAP creation failed: " + e);
        }
        return false;
    }          

This function creates the access point and the access point is discoverable from other devices. However, other devices are not able to connect to the WAP created. It gets stuck at Obtaining IP address.... When I try to connect to the WAP from desktop, the desktop self assigns an IP.

When the same hot spot is enabled from the settings manually then other devices are able to connect to the WAP without any problem.

Assuming tha the DHCP server is not getting started? Is there any additional step required to start the DHCP server after enabling the access point?

Krishna
  • 186
  • 1
  • 8
  • should you not pass netConfig to setWifiApMethod.invoke(wifiManager, null, true); instead of null ? Cf. https://stackoverflow.com/a/30542300/1959005 – Poutrathor Nov 20 '19 at 13:44
  • Also, seems like Google advice to not use such method anymore : https://medium.com/@jean.creuzedeschatelliers/how-to-activate-the-mobile-hotspot-on-android-programmatically-or-not-5931e44097e3 I did not dig further – Poutrathor Nov 20 '19 at 13:46
  • I tries passing a config and didn't help either. Yes indeed, these are not recommended options, however I need this for a very specific use case and targeted on Android 7.1 – Krishna Nov 20 '19 at 14:10
  • "> didn't help either" I think you should rather pass the options always and fix them to make it work ;) Maybe try to copy what work in other answers and then start to replace with what you need in the options. – Poutrathor Nov 20 '19 at 14:13
  • did you solve your problem ? – Poutrathor Nov 27 '19 at 17:42
  • Nope. Wasn't able to solve this. – Krishna Dec 13 '19 at 02:46

0 Answers0