1、注册广播
private void toRegister()
{
IntentFilter filter = new IntentFilter();
filter.addAction("android.net.wifi.WIFI_AP_STATE_CHANGED");
getContext().registerReceiver(mBroadcastReceiver, filter);
}
2、创建广播进行监听状态
private BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals("android.net.wifi.WIFI_AP_STATE_CHANGED")) {
//状态为:10---正在关闭;11---已关闭;12---正在开启;13---已开启
int state = intent.getIntExtra("wifi_state", 0);
if (state == 10) {
Log.d("热点","正在关闭");
} else if (state == 11) {
Log.d("热点&