Binil
Binil

Reputation: 454

How does ShareIt create and configure hotspot

I have to create a Wifi Hotspot with specific SSID and PASSWORD dynamically in my Android app project. I checked the ShareIt mobile app which creates a hotspot with SSID and PASSWORD and the receiver will connect to that hotspot, am expecting something similar to that.

Requirement is like, Android app should be able to create the Wifi hotspot with specific SSID and PASSWORD which will get from the server.

 WifiManager wifimanager = (WifiManager) context.getSystemService(context.WIFI_SERVICE);
WifiConfiguration wificonfiguration = null;
try {
    wificonfiguration = new WifiConfiguration();
    wificonfiguration.SSID = apName;
    // if WiFi is on, turn it off
    if(isApOn(context)) {
        wifimanager.setWifiEnabled(false);
        // if ap is on and then disable ap
        disableAp(context);
    }
    Method method = wifimanager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class, boolean.class);
    method.invoke(wifimanager, wificonfiguration, true);
    return true;
}
catch (Exception e) {
    e.printStackTrace();
}

I tried this code snippet, which is gives a NoSuchMethodException error.

Checking for Android version 9 Pie

Upvotes: 0

Views: 307

Answers (1)

Binil
Binil

Reputation: 454

App like ShareIt is creating hotspot using Local Only Hotspot

But in this case android is creating hotspot with a ssid and password that we cannot configure (Android is choosing a random ssid and password)

Upvotes: 0

Related Questions