• Stars
    star
    126
  • Rank 284,543 (Top 6 %)
  • Language
    Java
  • Created over 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Android WiFi Manager

Android WIFI控制

Step 1. Add the JitPack repository to your build file

Add it in your root build.gradle at the end of repositories:

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

Step 2. Add the dependency

dependencies {
        compile 'com.github.kongqw:AndroidWiFiManager:1.1.1'
}

初始化

// WIFI管理器
mWiFiManager = new WiFiManager(getApplicationContext());

打开WIFI

mWiFiManager.openWiFi();

关闭WIFI

mWiFiManager.closeWiFi();

添加WIFI开关状态的监听

mWiFiManager.setOnWifiEnabledListener(this);

回调

/**
 * WIFI开关状态的回调
 *
 * @param enabled true 打开 false 关闭
 */
@Override
public void onWifiEnabled(boolean enabled) {
    // TODO    
}

移除WIFI开关状态的监听

mWiFiManager.removeOnWifiEnabledListener();

获取WIFI列表

List<ScanResult> scanResults = mWiFiManager.getScanResults();

获取WIFI加密方式

mWiFiManager.getSecurityMode(scanResult)

注意:Android 6.0需要动态获取 Manifest.permission.ACCESS_FINE_LOCATION 或 Manifest.permission.ACCESS_COARSE_LOCATION 后,才能正常获取到WIFI列表。

添加获取WIFI列表的监听

mWiFiManager.setOnWifiScanResultsListener(this);

回调

/**
 * WIFI列表刷新后的回调
 *
 * @param scanResults 扫描结果
 */
@Override
public void onScanResults(List<ScanResult> scanResults) {
    // TODO
}

mWiFiManager.getScanResults(); 是返回当前的WIFI列表,回调返回的是扫描更新以后新的WIFI列表。

移除获取WIFI列表的监听

mWiFiManager.removeOnWifiScanResultsListener();

连接到开放网络

mWiFiManager.connectOpenNetwork(scanResult.SSID);

连接到WPA/WPA2网络

mWiFiManager.connectWPA2Network(scanResult.SSID, password);

连接到WEP网络

mWiFiManager.connectWEPNetwork(scanResult.SSID, password);

添加连接WIFI的监听

mWiFiManager.setOnWifiConnectListener(this);

回调

/**
 * WIFI连接的Log得回调
 *
 * @param log log
 */
@Override
public void onWiFiConnectLog(String log) {
    Log.i(TAG, "onWiFiConnectLog: " + log);
    // TODO
}

/**
 * WIFI连接成功的回调
 *
 * @param SSID 热点名
 */
@Override
public void onWiFiConnectSuccess(String SSID) {
    Log.i(TAG, "onWiFiConnectSuccess:  [ " + SSID + " ] 连接成功");
    // TODO
}

/**
 * WIFI连接失败的回调
 *
 * @param SSID 热点名
 */
@Override
public void onWiFiConnectFailure(String SSID) {
    Log.i(TAG, "onWiFiConnectFailure:  [ " + SSID + " ] 连接失败");
    // TODO
}

移除连接WIFI的监听

mWiFiManager.removeOnWifiConnectListener();

断开网络连接

mWiFiManager.disconnectWifi(connectionInfo.getNetworkId());

删除网络配置

只能删除自己创建的配置,其他应用生成的配置需要Root权限才可以删除。

mWiFiManager.deleteConfig(wifiConfiguration.networkId);

More Repositories

1

OpenCVForAndroid

目标检测&目标追踪&人脸检测&人脸识别
Java
2,048
star
2

AndroidSerialPort

Android串口通信示例
Java
719
star
3

AndroidRocker

Android 摇杆
Java
276
star
4

NetworkMonitor

Android 全局网络变化监听
Kotlin
45
star
5

Android-CheckView

Android端手机验证码的生成
Java
38
star
6

WeChatHelper

WeChatHelper for androidx ,微信开放平台封装,包含微信分享、微信授权登录、微信支付
Kotlin
25
star
7

CombinedChartDemo

模拟自选股
Java
21
star
8

AndroidRadarScanView

Android Radar Scan 雷达扫描控件
Java
21
star
9

AndroidSoundManagerDemo

Android左右声道控制的示例程序
Java
17
star
10

AndroidBluetoothManager

Android Bluetooth Library
Java
17
star
11

PermissionsManager

Android 6.0 动态权限管理器
Kotlin
16
star
12

KqwOpenCVFeaturesDemo

图像边缘检测
Java
16
star
13

AndroidAssistiveTouch

模仿iphone AssistiveTouch
Java
13
star
14

AndroidUsbSerialDemo

Android USB 串口通信
Java
13
star
15

KqwOpenCVBlurDemo

使用OpenCV实现图片虚化处理
Java
9
star
16

CountDownTimerDemo

发送验证码倒计时
Java
9
star
17

QQHelper

QQHelper for androidx,QQ开放平台功能封装,包含QQ分享,QQ授权登录
Kotlin
9
star
18

AndroidVolumeManager

Android 音量控制
Java
7
star
19

KqwBluetoothDemo

Java
5
star
20

KqwBottomNavigation

安卓底部导航栏
Java
3
star
21

KqwHciDemo

灵云语音
Java
3
star
22

VolumeController

Java
2
star
23

RecyclerViewItemClickDemo

自定义高效支持点击监听的RecyclerView
Java
2
star
24

SelectorDemo

状态选择器示例Demo
Java
2
star
25

TuringSDK

Java
2
star
26

KqwHciTtsDemo

灵云语音
Java
1
star
27

KTools

常用工具梳理
Kotlin
1
star
28

ShapeView

Kotlin
1
star
29

FirstOpenCVDemo

OpenCV的部署
Java
1
star