我知道如何使用以下方法在android中使用反射来开启/关闭wifi热点。如何在Android 8.0(Oreo)中以编程方式打开/关闭wifi热点
private static boolean changeWifiHotspotState(Context context,boolean enable) {
try {
WifiManager manager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
Method method = manager.getClass().getDeclaredMethod("setWifiApEnabled", WifiConfiguration.class,
Boolean.TYPE);
method.setAccessible(true);
WifiConfiguration configuration = enable ? getWifiApConfiguration(manager) : null;
boolean isSuccess = (Boolean) method.invoke(manager, configuration, enable);
return isSuccess;
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
但上述方法不适用于Android 8.0(奥利奥)。
当我在Android 8.0中执行上面的方法时,我在logcat中获得了下面的语句。
com.gck.dummy W/WifiManager: com.gck.dummy attempted call to setWifiApEnabled: enabled = true
是否有任何其他的方式,在Android 8.0
是否要关闭wifi或热点 – MrAppMachine
我想打开/关闭热点...不是wifi ... – Chandrakanth
是否有可能他们删除了这种方式在Android O ?打开wifi热点不是Android SDK的一部分。因此,这种方式使用反射是有点hacky – Rafa