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");
    }
    }
    }
    }
  • 相关阅读:
    django ajax报错解决:You called this URL via POST, but the URL doesn't end in a slash and you have APPEND_SLASH set.
    django使用session报错:no such table: django_session
    centos7下yum安装mariadb
    pip报错解决:EnvironmentError: mysql_config not found
    django报错解决:view must be a callable or a list/tuple in the case of include().
    onpageshow和onpagehide
    深入理解Linux的CPU上下文切换
    看完就彻底懂了红黑树!红黑树的插入、删除、左旋、右旋
    shell根据csv生成sql
    shell中的EOF用法
  • 原文地址:https://www.cnblogs.com/adamli/p/13140630.html
Copyright © 2011-2022 走看看