HotsSpotReceiver 热点

Posted adamli

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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");
}
}
}
}

以上是关于HotsSpotReceiver 热点的主要内容,如果未能解决你的问题,请参考以下文章

nginx代理https

Spark Streaming快速入门之WordCount

mq_receive()

安卓手机如何设置wifi热点?

Android11 设置默认热点名称和热点密码密码长度

Android11 设置默认热点名称和热点密码密码长度