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"/>
对于上述有问题的 SO链接:
此功能不可用,即尚未实施。有关更多信息,请查看Google 正式将状态标记为Status: Won't Fix (Obsolete)的链接
希望这会帮助你。谢谢!
推荐阅读
- ios - 避免由于单元格中其他按钮的高度扩展而导致按钮高度扩展
- forms - react native 中的 ref 是什么,我什么时候应该使用 ref?
- azure-data-factory-2 - Blob 到 azure sql db 加载
- java - 在jackson中将一个字段从字符串更改为json对象
- javascript - 如何通过 create-react-app 项目在 SASS、SCSS 和 LESS 之间选择使用哪一个
- angular - 如何获取当前模块的所有路由?
- flutter - 如何在 Flutter 中的 HTTP 发布请求中传递标头?
- java - 蓝牙发现问题
- azure - Power BI 架构
- linux-kernel - 如何判断 System.map 中的符号是变量还是函数?