如何检测的WiFi网络共享状态 [英] How to detect WiFi tethering state

查看:188
本文介绍了如何检测的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();
}
}

正如你所看到的<一个href="http://stackoverflow.com/questions/8007361/is-there-a-way-to-check-whether-tethering-is-active">here

这篇关于如何检测的WiFi网络共享状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆