0

I was able to know whether the device is connected to wifi, Now i want to know whether the android device is turned on wifi hotspot, how to determine whether the android device is turned on wifi hotspot. is it possible?
Thanks.

eric
  • 35
  • 4

1 Answers1

2

Try this way

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.map_view);

    prefs = new UserPrefs(this);

}

final WifiManager wifi = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
public static boolean isSharingWiFi(final WifiManager manager)
{
    try
    {
        final Method method = manager.getClass().getDeclaredMethod("isWifiApEnabled");
        method.setAccessible(true); 
        return (Boolean) method.invoke(manager);
    }
    catch (Exception e)
    {
     e.printStackTrace();
     Toast.makeText(getApplicationContext(), ""+e, Toast.LENGTH_LONG).show();
    }

    return false;
}

AndroidManifest.xml:

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
Maveňツ
  • 1
  • 12
  • 50
  • 89