This module verify app connectivity using brodcastreceivers.
- minSdkVersion 21
- targetSdkVersion 29
//build.gradle (app level)
dependencies {
// ...
//di
implementation 'com.google.dagger:dagger-android:2.16'
kapt 'com.google.dagger:dagger-android-processor:2.16'
kapt 'com.google.dagger:dagger-compiler:2.16'
implementation 'com.google.dagger:dagger-android-support:2.15'
implementation "androidx.lifecycle:lifecycle-extensions:2.2.0"
// ...
}
@Component(
modules = [
//...
VerifyConnectivityModule::class
]
)
interface AppComponent {
//...
}
This library is private you must config your gradle.properties on your project and add maven repo url and set credentials. Ex:.
gradle.properties
authToken=jp_8jkk1tjtcqlmrghvio2j2njb7s
build.gradle (project level)
allprojects {
repositories {
...
maven {
url "https://jitpack.io"
credentials { username authToken }
}
}
}
build.gradle (app level)
dependencies {
implementation 'com.github.danielideriba:VerifyConnectivityModule:VERSION'
}
class YourActivity : AppCompatActivity(), ConnectivityReceiver.ConnectivityReceiverListener {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_youractivity)
registerReceiver(ConnectivityReceiver(), IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION))
}
override fun onResume() {
super.onResume()
ConnectivityReceiver.connectivityReceiverListener = this
}
override fun onNetworkConnectionChanged(isConnected: Boolean) {
showMessage(isConnected)
}
private fun showMessage(isConnected: Boolean) {
if (!isConnected) {
WarningScreenActivity.start(this)
Timber.d("You are offline now.")
} else {
Timber.d("You are online now.")
}
}
}