• HotsSpotReceiver 热点


    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");
    }
    }
    }
    }
  • 相关阅读:
    create-react-app 修改 webpack output.publicPath
    洛谷 P1282 多米诺骨牌 (01背包)
    UVa 1627
    UVa 1626
    UVa 11584
    UVa 11400
    UVa 116
    UVa 1347 Tour (dp)
    树形背包小结
    数据流图题目一
  • 原文地址:https://www.cnblogs.com/adamli/p/13140630.html
Copyright © 2020-2023  润新知