public static boolean setHotspotNameAndPassword(String newName,String password, Context context) {
try {
WifiManager wifiManager = (WifiManager) context.getSystemService(context.WIFI_SERVICE);
Method getConfigMethod = wifiManager.getClass().getMethod("getWifiApConfiguration");
WifiConfiguration wifiConfig = (WifiConfiguration) getConfigMethod.invoke(wifiManager);
wifiConfig.preSharedKey=password;
wifiConfig.SSID = newName;
Method setConfigMethod = wifiManager.getClass().getMethod("setWifiApConfiguration", WifiConfiguration.class);
setConfigMethod.invoke(wifiManager, wifiConfig);
return true;
}
catch (Exception e) {
e.printStackTrace();
return false;
}
这对我来说是工作!修改设置。
但我找不到在 Android 7.0+ 上打开/关闭热点的方法