如何检测的WiFi网络共享状态

问题描述:

我想知道如何检测的WiFi网络共享的状态。我看到一篇文章: Android 2.3的wifi热点API 但它不科技工作!它总是返回WIFI_AP_STATE_DISABLED = 1。它不依赖于无线束缚的真实状态。

I want to know how to detect state of WiFi tethering. I've seen an article: Android 2.3 wifi hotspot API But it doesn't work! It returns always WIFI_AP_STATE_DISABLED = 1. It doesn't depend on real state of WiFi tethering.

使用反射:

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