我想知道如何检测 WiFi 网络共享的状态。我看过一篇文章:Android 2.3 wifi热点API https://stackoverflow.com/questions/7048922/android-2-3-wifi-hotspot-api但这不起作用!它始终返回 WIFI_AP_STATE_DISABLED = 1。它不依赖于 WiFi 网络共享的真实状态。
使用反射:
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
Method[] wmMethods = wifi.getClass().getDeclaredMethods();
for (Method method: wmMethods) {
if (method.getName().equals("isWifiApEnabled")) {
try {
boolean isWifiAPenabled = method.invoke(wifi);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}
如你看到的here https://stackoverflow.com/questions/8007361/is-there-a-way-to-check-whether-tethering-is-active
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)