public boolean setWifiApEnabled(boolean enabled) {
if (enabled) { // disable WiFi in any case wifiManager.setWifiEnabled(false); } try { WifiConfiguration apConfig = new WifiConfiguration(); apConfig.SSID = "123456"; // apConfig. apConfig.allowedKeyManagement .set(WifiConfiguration.KeyMgmt.WPA_PSK); apConfig.preSharedKey = "123456789"; Method method = wifiManager.getClass().getMethod( "setWifiApEnabled", WifiConfiguration.class, Boolean.TYPE); return (Boolean) method.invoke(wifiManager, apConfig, enabled); } catch (Exception e) { Log.e(TAG, "Cannot set WiFi AP state", e); return false; } } |
|