Skip to content

Commit 7cd7622

Browse files
author
kongqw
committed
update readme
1 parent 4a4159c commit 7cd7622

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

README.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,14 @@ dependencies {
3737
NetworkMonitorManager.getInstance().init(this)
3838
```
3939

40-
### 注册
40+
### 注册与反注册
4141

42-
在需要监听网络状态的页面进行注册
42+
在需要监听网络状态的页面进行注册与反注册
4343

4444
``` kotlin
4545
NetworkMonitorManager.getInstance().register(this)
4646
```
4747

48-
### 反注册
49-
5048
``` kotlin
5149
NetworkMonitorManager.getInstance().unregister(this)
5250
```
@@ -93,6 +91,18 @@ fun onNetWorkStateChange2(networkState: NetworkState) {
9391
}
9492
```
9593

94+
### 判断当前是否有网络连接
95+
96+
``` kotlin
97+
val hasNetworkCapability: Boolean = NetworkStateUtils.hasNetworkCapability(applicationContext)
98+
```
99+
100+
### 获取当前的网络状态
101+
102+
``` kotlin
103+
val networkState: NetworkState = NetworkStateUtils.getNetworkState(applicationContext)
104+
```
105+
96106
## 混淆
97107
```
98108
-keepattributes *Annotation*

app/src/main/java/com/kongqw/networkmonitor/MainActivity.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ class MainActivity : AppCompatActivity() {
2323
NetworkMonitorManager.getInstance().register(this)
2424

2525
btn_action_1?.setOnClickListener {
26-
val hasNetworkCapability = NetworkStateUtils.hasNetworkCapability(applicationContext)
26+
val hasNetworkCapability: Boolean = NetworkStateUtils.hasNetworkCapability(applicationContext)
2727
Toast.makeText(applicationContext, if (hasNetworkCapability) "当前有网络" else "当前无网络", Toast.LENGTH_SHORT).show()
2828
}
2929
btn_action_2?.setOnClickListener {
30-
val networkState = NetworkStateUtils.getNetworkState(applicationContext)
30+
val networkState: NetworkState = NetworkStateUtils.getNetworkState(applicationContext)
3131
Toast.makeText(applicationContext, "当前网络类型:$networkState", Toast.LENGTH_SHORT).show()
3232
}
3333
}

0 commit comments

Comments
 (0)