File tree Expand file tree Collapse file tree 2 files changed +16
-6
lines changed
app/src/main/java/com/kongqw/networkmonitor Expand file tree Collapse file tree 2 files changed +16
-6
lines changed Original file line number Diff line number Diff line change @@ -37,16 +37,14 @@ dependencies {
3737NetworkMonitorManager .getInstance().init (this )
3838```
3939
40- ### 注册
40+ ### 注册与反注册
4141
42- 在需要监听网络状态的页面进行注册
42+ 在需要监听网络状态的页面进行注册与反注册
4343
4444``` kotlin
4545NetworkMonitorManager .getInstance().register(this )
4646```
4747
48- ### 反注册
49-
5048``` kotlin
5149NetworkMonitorManager .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*
Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments