3

I can't find in the doc how to retrieve if device is configured as a portable hotspot.

I've read How to detect if a network is (configured as) a mobile hotspot on Android? but I don't know if the feature has been implemented?

narb
  • 958
  • 1
  • 13
  • 39

1 Answers1

2

You can use below code to check if Tethering is enabled or not on your device:

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;
}

Don't forget to add below permission in AndroidManifest.xml

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>

For the SO link mentioned above in question:

This feature is not available i.e. has not been implemented. For more information check this link where Google officially marked the status as Status: Won't Fix (Obsolete)

Hope this will help you. Thanks!

Vikasdeep Singh
  • 20,983
  • 15
  • 78
  • 104
  • The above code tells me if my device is connected to a portable hotspot, not if my device is the access point, right? Why is the status: Won't Fix (Obsolete)? Thanks for the info update and sharing the code :) – narb Aug 15 '18 at 06:40