Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create Wifi Hotspot Configuration in android

I am using android 4.1.1 ... I am making an application that allows the user to make his own network using Wifi Hotspot and then the clients can connect to it and share data. I have successfully created the Wifi hotspot in android but I cannot configure it for the purpose. Is there any way to configure Wifi Hotspot on android through coding ??

like image 265
Khan Umair Avatar asked Jun 17 '13 16:06

Khan Umair


People also ask

Can I create a Wi-Fi hotspot with my Android phone?

You can use your phone's mobile data to connect another phone, tablet, or computer to the internet. Sharing a connection this way is called tethering or using a hotspot. Some phones can share Wi-Fi connection by tethering. Most Android phones can share mobile data by Wi-Fi, Bluetooth, or USB.

How do I create my own Wi-Fi hotspot?

To turn your Android phone into a hotspot, go to Settings, then Mobile Hotspot & Tethering. Tap on Mobile Hotspot to turn it on, set the name of your network and set a password. You connect a computer or tablet to your phone's Wi-Fi hotspot just as you would connect to any other Wi-Fi network.


1 Answers

This answer maybe outdated!

if(wifiManager.isWifiEnabled())
{
    wifiManager.setWifiEnabled(false); 
}

WifiConfiguration netConfig = new WifiConfiguration();

netConfig.SSID = "MyAP";
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{
    Method setWifiApMethod = wifiManager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class, boolean.class);
    boolean apstatus=(Boolean) setWifiApMethod.invoke(wifiManager, netConfig,true);

    Method isWifiApEnabledmethod = wifiManager.getClass().getMethod("isWifiApEnabled"); 
    while(!(Boolean)isWifiApEnabledmethod.invoke(wifiManager)){};
    Method getWifiApStateMethod = wifiManager.getClass().getMethod("getWifiApState"); 
    int apstate=(Integer)getWifiApStateMethod.invoke(wifiManager);
    Method getWifiApConfigurationMethod = wifiManager.getClass().getMethod("getWifiApConfiguration");
    netConfig=(WifiConfiguration)getWifiApConfigurationMethod.invoke(wifiManager);
    Log.e("CLIENT", "\nSSID:"+netConfig.SSID+"\nPassword:"+netConfig.preSharedKey+"\n");

} catch (Exception e) {
    Log.e(this.getClass().toString(), "", e);
}
like image 79
mizdler Avatar answered Sep 28 '22 07:09

mizdler