zoukankan      html  css  js  c++  java
  • 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");
    }
    }
    }
    }
  • 相关阅读:
    Kmeans中文聚类
    第四周周总结
    数据清洗第一天
    第三周周总结
    关于sqoop上传mysql数据到hive报错的问题
    天津东软实训第十一天——Hive连接JDBC
    天津东软实训第十天——Hive配置
    天津东软实训第九天——MapReduce实战
    天津东软实训第八天------倒排索引
    Intellij IDEA 创建maven项目,利用API操作HDFS
  • 原文地址:https://www.cnblogs.com/adamli/p/13140630.html
Copyright © 2011-2022 走看看