Saturday, December 21, 2013

Android - Turn WiFi Hotspot On and Off Programmatically


Programmatically turn WiFi Hotspot On and Off on android platform using following permissions in Manifest file.

android.permission.ACCESS_WIFI_STATE
android.permission.CHANGE_WIFI_STATE

and following code

WifiManager wifi = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);

WifiConfiguration wifi_config = null;

wifi.setWifiEnabled(false); //True or False

//There is no direct call so use following... //USE REFLECTION ON THE METHOD NAMED //SetWifiAPEnabled//
Method methodAP = wifi.getClass().getMethod("setWifiApEnabled", WifiConfig.class, boolean.class);

methodAP.invoke(wifi, wifi_config, false); //True or False


    

No comments:

Post a Comment