Simple network status tracker for Android like an iOS Reachability library
Create a Reachability instance:
mReachability = new Reachability(view.getContext())
Add an observer for reachability status changes:
mReachability.addListener(object : ReachabilityStateObserver {
override fun onReachabilityStateChange(newState: Reachability.State) {
}
})
or simply implement ReachabilityStateObserver
to your class:
class YourClass : ReachabilityStateObserver {}
and add this
as a listener:
mReachability.addListener(this)
You should use startNotifier()
method for start listening of Network state changes:
mReachability.startNotifier()
When you don't need to listen changes, you can use stopNotifier()
method:
mReachability.stopNotifier()
Please, don't forget to remove your observer with removeListener()
method if it's not needed anymore:
mReachability.removeListener(this)
Also, you can see an usage example here.
Maven:
<dependency>
<groupId>ua.eshcherbinock</groupId>
<artifactId>reachability</artifactId>
<version>0.0.7</version>
<type>pom</type>
</dependency>
Gradle:
implementation 'ua.eshcherbinock:reachability:0.0.7'
You can see the latest version number here or download library directly.
- Fork it - https://github.com/Eugene-Shcherbinock/Reachability/fork
- Create your feature(fix) branch
git checkout -b some-feature
- Commit your changes
git commit -m 'add some feature'
- Push to the branch
git push origin my-new-feature
- Create new Pull Request here
Copyright 2018 Eugene Shcherbinock
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.