class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
NetworkLiveData.getInstance().observe(this, Observer {
when (it) {
NetworkState.CONNECT -> {
text.text = "网络已连接"
}
NetworkState.NONE -> {
text.text = "网络中断"
}
NetworkState.CELLULAR -> {
text.text = "移动网络已连接"
}
NetworkState.WIFI -> {
text.text = "WIFI已连接"
}
}
})
}
}
smallmarker/ZL-NetworkLiveData
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
利用LiveData+NetworkCallback实现网络监控功能
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published