0

I have a prototype Android app that is listening mobile function state continuously like Hotspot. For bluetooth detect, I am using registerContentObserver() to get the latest state and it will notify me in custom ContentObserver.

So for Hotspot,

  1. How can I detect hotspot on/off
  2. Check any device connected through hotspot or not

Thanks in advance.

Dhruv
  • 1,862
  • 3
  • 20
  • 38

1 Answers1

0

Check if hotspot is enabled or not

Method method = wifiManager.getClass().getDeclaredMethod("getWifiApState");
    method.setAccessible(true);
    int actualState = (Integer) method.invoke(wifiManager, (Object[]) null);

Different States

public static int AP_STATE_DISABLING = 10;
public static int AP_STATE_DISABLED = 11;
public static int AP_STATE_ENABLING = 12;
public static int AP_STATE_ENABLED = 13;
public static int AP_STATE_FAILED = 14;

For detecting clients you can use android.net.wifi.WIFI_HOTSPOT_CLIENTS_CHANGED broadcast receiver.

Imran Ali
  • 321
  • 2
  • 13
  • After goggling I posted question on SO. This answer is already posted [here](http://stackoverflow.com/a/14405339/2078074). – Dhruv Mar 23 '17 at 13:12