I\'m using in the app
setWifiApEnabled()
from Hidden API (access by reflection). In some older phone it´s working (also with Samsung Galaxy S3,
Try This.
ConnectivityManager cman = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
Method[] methods = cman.getClass().getMethods();
try
{
wifiManager.setWifiEnabled(false);
Method enableWifi = wifiManager.getClass().getMethod("setWifiApEnabled", WifiConfiguration.class, boolean.class);
String ssid = " " //your SSID
String pass = " " // your Password
WifiConfiguration myConfig = new WifiConfiguration();
myConfig.SSID = ssid;
myConfig.preSharedKey = pass ;
myConfig.status = WifiConfiguration.Status.ENABLED;
myConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
myConfig.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
myConfig.allowedProtocols.set(WifiConfiguration.Protocol.WPA);
myConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
myConfig.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
myConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
myConfig.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
result = (Boolean) enableWifi.invoke(wifiManager, myConfig, true);
}
catch (Exception e)
{
e.printStackTrace();
result = false;
}
In case of your exception try add this permission to your Manifest android.permission.WRITE_SETTINGS