a library for check network available on Android, which uses ping or request url to get the real network status.
Gradle dependency
In your module build.gradle
add follow
dependencies {
compile 'com.yan.netmanager:netmanager:1.2.0'
}
-
Download this repo and import eclipse as library project. Make your project depend on this project.
-
Optional——Config the library in your application onCreate method or activity onCreate method. Use like below config ping host and request url(optional, default is "http://www.baidu.com"):
NetStatusManager.getInstance().config("http://www.baidu.com", "http://www.baidu.com");
config use ping or request url(optional, default is request url)
NetStatusManager.getInstance().setCheckType(false);
config request timeout ( optional, default connect time out is 2000ms and read time out is 2000ms)
NetStatusManager.getInstance().configTimeOut(2000, 2000)
-
In your activity onResume method, add
NetStatusManager.getInstance().refreshStatus();
-
When you want to access network state, use like below
NetStatusManager.getInstance().getNetStatus()
which return the network status.