Create Your Own SSID and create Hotspot On Click ( Open Connection)

To start hotspot you have to add few lines and its done

WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
wifi.setWifiEnabled(false);
Method[] methods = wifi.getClass().getDeclaredMethods();
   for (Method method : methods) {
       if (method.getName().equals("setWifiApEnabled")) {
           try {
           
               method.invoke(wifi, null, false);
           } catch (Exception ex) {
           }
           break;
       }
   }
setssid(true);


private void setssid(boolean enable){
WifiManager mWifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
try{
 Method getWifiConfig = mWifiManager.getClass().getMethod("getWifiApConfiguration",null);
       WifiConfiguration wifiConf  = (WifiConfiguration)getWifiConfig.invoke(mWifiManager, null);
       wifiConf.SSID = "Radio Channel";
     wifiConf.allowedAuthAlgorithms.set(WifiConfiguration.AuthAlgorithm.OPEN);
       wifiConf.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
       wifiConf.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
       wifiConf.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE);
       Method setWifiConfig = mWifiManager.getClass().getMethod("setWifiApConfiguration",WifiConfiguration.class);
       setWifiConfig.invoke(mWifiManager,wifiConf);
       Method[] methods = mWifiManager.getClass().getDeclaredMethods();
   for (Method method : methods) {
       if (method.getName().equals("setWifiApEnabled")) {
           try {
           
               method.invoke(mWifiManager, null, enable);
           } catch (Exception ex) {
           }
           break;
       }
   }
}
     

catch(Exception e){e.printStackTrace();}

}

Comments

Popular posts from this blog

Making Bootable Pendrive with .bat file

Ek Beej Tha Gaya Bahut Hee Gaharaee Mein Boya - Nanha Paudha

R-W-W (Real, Win, Worth it ) - Boost your idea