我正在尝试以编程方式更改Android AP Wifi密码,但不幸的是停止了工作。 使用Android 4.2工作正常,但4.4 Kitkat已停止。
我通过反射使用 setWifiApConfiguration 。 有人知道谷歌是否阻止了这个伎俩?
我的代码:
//Get WifiApConfiguration
public WifiConfiguration getWifiApConfiguration() {
try {
Method method = mWifiManager.getClass().getMethod("getWifiApConfiguration");
return (WifiConfiguration) method.invoke(mWifiManager);
} catch (Exception e) {
Log.e("", "", e);
return null;
}
}
//Setting new password
public void changeConfiguration() {
WifiConfiguration mWifiConfiguration = mWifiManager.getWifiApConfiguration();
mWifiConfiguration.preSharedKey = "NewPassword";
mWifiConfiguration.allowedKeyManagement.set(KeyMgmt.WPA_PSK);
mWifiConfiguration.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
Method method = mWifiManager.getClass().getMethod("setWifiApConfiguration", WifiConfiguration.class);
boolean result = method.invoke(mWifiManager, pConfiguration);
Log.e("WIFI", String.valueOf(result));
}