我可以检查程序呼叫android设备是否激活了绑定吗?
我刚看了WifiManager的课。来自WifiInfo的所有变量显示的值与设备上关闭WIFI时的值相同。
Thnak,致以最好的问候
发布于 2011-11-04 18:02:29
尝试使用反射,如下所示:
WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
Method[] wmMethods = wifi.getClass().getDeclaredMethods();
for(Method method: wmMethods){
if(method.getName().equals("isWifiApEnabled")) {
try {
method.invoke(wifi);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
}(它返回一个Boolean)
正如Dennis建议的那样,最好使用以下代码:
final Method method = manager.getClass().getDeclaredMethod("isWifiApEnabled");
method.setAccessible(true); //in the case of visibility change in future APIs
return (Boolean) method.invoke(manager);(经理是WiFiManager)
发布于 2013-12-07 03:29:46
首先,您需要获取WifiManager:
Context context = ...
final WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);然后:
public static boolean isSharingWiFi(final WifiManager manager)
{
try
{
final Method method = manager.getClass().getDeclaredMethod("isWifiApEnabled");
method.setAccessible(true); //in the case of visibility change in future APIs
return (Boolean) method.invoke(manager);
}
catch (final Throwable ignored)
{
}
return false;
}此外,您还需要在AndroidManifest.xml中请求权限:
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>https://stackoverflow.com/questions/8007361
复制相似问题