Reputation: 1266
How to know wifi hotspot was close by user? I asume that there should have event to notify hotspot state changed. I looked into WifiManager.java, I found a releated action.
below action is hiden,
public static final String WIFI_AP_STATE_CHANGED_ACTION = "android.net.wifi.WIFI_AP_STATE_CHANGED";
can you give me some point to get known hotspot was closed?
Upvotes: 0
Views: 207
Reputation: 1914
It can be done using broadcast receiver for WIFI_AP_STATE_CHANGED.
Declare the receiver in Manifest as android.net.wifi.WIFI_AP_STATE_CHANGED action and include all necessory permissions to use WiFi. The on receive function of Broadcast receiver is as follows
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if ("android.net.wifi.WIFI_AP_STATE_CHANGED".equals(action)) {
int hotSpotState = intent.getIntExtra("wifi_state",
0);
// Your code goes here
}
}
Upvotes: 2