DEV Community

Cover image for ConnectivityLifeData for API 30 & lower APIs
Mbuodile Obiosio
Mbuodile Obiosio

Posted on • Edited on

ConnectivityLifeData for API 30 & lower APIs

I made this super lightweight library to enable Android Developers handle network changes across API 16 to 30.

GitHub logo mbobiosio / LiveDataConnection

A super simple, super light-weight lifecycle aware solution written in Kotlin that helps you to capture network connectivity events with support for lower APIs

Codacy Badge Maintainability Rating Platform API Vulnerabilities


A super simple, super light-weight lifecycle aware solution written in Kotlin that helps you to capture network connectivity events with support for lower APIs

USAGE

Codacy Badge

Including in your project

Add below codes to your root build.gradle

allprojects {
   repositories {
      maven { url 'https://jitpack.io' }
   }
}

Add connectionlivedata dependency to your project's module build.gradle

implementation 'com.github.mbobiosio:connectionlivedata:1.0.3'
Enter fullscreen mode Exit fullscreen mode
  • Use in your Activity
 val connectionLiveData = ConnectionLiveData(this)
 connectionLiveData.observe(this, {
     Log.d("Status", "$it")
 })
Enter fullscreen mode Exit fullscreen mode
  • Use in your Fragment
 val connectionLiveData = ConnectionLiveData(activity as Activity)
 connectionLiveData.observe(viewLifecycleOwner, {
    Log.d("Status", "$it")
 })
Enter fullscreen mode Exit fullscreen mode

Contribute

If you want to contribute to this app, you're always welcome! See Contributing Guidelines.

📝 License

This project is released under the MIT license. See LICENSE for details.

MIT License
Copyright (c) 2020 Mbuodile Obiosio

Permission is hereby

Feel to create a pull request.

Top comments (0)