Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to check whether tethering is active?

can I check programmaticall wheter the android device has tethering activated?

I just watched the WifiManager class. All vatraibles from the WifiInfo show the same values as iff the WIFI is turned off on the device.

Thnaks, best regards

like image 259
softwaresupply Avatar asked Nov 04 '11 09:11

softwaresupply


1 Answers

First, you need to get WifiManager:

Context context = ...
final WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);

Then:

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

Also you need to request a permission in AndroidManifest.xml:

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
like image 100
Denis Gladkiy Avatar answered Sep 28 '22 02:09

Denis Gladkiy