我在文档中找不到如何检索设备是否配置为便携式热点。
我已阅读如何检测网络是否(配置为)Android 上的移动热点?但我不知道该功能是否已实现?
您可以使用以下代码检查您的设备上是否启用了网络共享:
private static Method isWifiApEnabledMethod;
public static boolean isWifiApEnabled(WifiManager wifiManager) {
if (isWifiApEnabledMethod == null) {
try {
isWifiApEnabledMethod = wifiManager.getClass().getDeclaredMethod("isWifiApEnabled");
isWifiApEnabledMethod.setAccessible(true); //in the case of visibility change in future APIs
} catch (NoSuchMethodException e) {
Log.w(TAG, "Can't get method by reflection", e);
}
}
if (isWifiApEnabledMethod != null) {
try {
return (Boolean) isWifiApEnabledMethod.invoke(wifiManager);
} catch (IllegalAccessException e) {
Log.e(TAG, "Can't invoke method by reflection", e);
} catch (InvocationTargetException e) {
Log.e(TAG, "Can't invoke method by reflection", e);
}
}
return false;
}
不要忘记在
AndroidManifest.xml
添加以下权限
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
对于上面提到的SOlink:
此功能不可用,即尚未实现。 有关更多信息,请查看this链接,其中 Google 正式将状态标记为状态:不会修复(已过时)