标签:date cti action ons context tac stat err ica
package com.android.demo.lileidemo.listener;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Handler;
import com.android.demo.lileidemo.MyApplication;
import com.android.demo.lileidemo.constant.AppConstants;
/**
* date: 04/08/2020.
* author: lilei.
* Android8.0 should dynamic registration monitoring.
*/
public class HotsSpotReceiver extends BroadcastReceiver {
public static String TAG = AppConstants.APP_TAG + "HotsSpotReceiver";
private Handler mWorker;
private static volatile HotsSpotReceiver mInstance;
public static final int WIFI_AP_CLOSEING = 10; //wifi hot is closeing
public static final int WIFI_AP_CLOSE_SUCCESS = 11; //wifi hot close success
public static final int WIFI_AP_OPENING = 12; //WiFi hot is opening
public static final int WIFI_AP_OPEN_SUCCESS = 13; //WiFi hot open success
public HotsSpotReceiver() {
mWorker = new Handler();
}
/**
* get Instance.
*
* @return instance.
*/
public static HotsSpotReceiver getInstance() {
if (mInstance == null) {
synchronized (HotsSpotReceiver.class) {
if (mInstance == null) {
mInstance = new HotsSpotReceiver();
}
}
}
return mInstance;
}
/**
* Register Ivi State Change Listener and start HotsSpot monitor.
*/
public void registerIviStateChangeListener() {
//LogUtil.d(TAG + "registerIviStateChangeListener()");
registerReceiver();
}
/**
* registerReceiver.
*/
private void registerReceiver() {
//LogUtil.d(TAG + "registerReceiver private");
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction("android.net.wifi.WIFI_AP_STATE_CHANGED");
MyApplication.getAppContext().registerReceiver(HotsSpotReceiver.getInstance(),
intentFilter);
}
/**
* unregisterReceiver.
*/
public void unregisterReceiver() {
MyApplication.getAppContext().unregisterReceiver(HotsSpotReceiver.getInstance());
}
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals("android.net.wifi.WIFI_AP_STATE_CHANGED")) {
int state = intent.getIntExtra("wifi_state", 0);
if (state == WIFI_AP_CLOSEING) {
//LogUtil.d(TAG + "wifi hot is closeing");
} else if (state == WIFI_AP_CLOSE_SUCCESS) {
//LogUtil.d(TAG + "wifi hot close success");
} else if (state == WIFI_AP_OPENING) {
//LogUtil.d(TAG + "WiFi hot is opening");
} else if (state == WIFI_AP_OPEN_SUCCESS) {
//LogUtil.d(TAG + "WiFi hot open success");
}
}
}
}
标签:date cti action ons context tac stat err ica
原文地址:https://www.cnblogs.com/adamli/p/13140630.html