如何查找设备是否配置为便携式热点

How to find if the device is configured as a portable hotspot

如果设备配置为便携式热点,我无法在文档中找到如何检索。

我已经阅读了 How to detect if a network is (configured as) a mobile hotspot on 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 link,其中 Google 正式将状态标记为 状态:不会修复(已过时)

希望对您有所帮助。谢谢!