Md. Mahmudul Hasan Shohag
3 min readMar 2, 2020

Yet another No Internet Dialog library for Android!

Photo by NASA on Unsplash

A couple of months ago I found a library, called “NoInternetDialog”. It’s an awesome Android library to notify users when there is no active internet connection!

But the library is not currently maintained. And it has a serious crash issue! I wanted to fork and fix the bug, but it has a lot of depreciated codes and written in Java 😑!

So finally I get inspired by the idea 😉 and create a new library,

Oops! No Internet!

No internet dialog and snackbar for rescue!

It’s written in Kotlin. Just initialize it in onResume and destroy it in onPause. that’s it!

Oops! No Internet!: No Internet & Airplane mode dialog

If you don’t like the dialog, the library also had a NoInternetSnackbar! It will show a Snackbar when there is no active Internet connection.

Oops! No Internet!: No Internet & Airplane mode snackbar

The library is customizable.

How to use it?

Step 1. Add the JitPack repository to your build file

Add it to your root build.gradle at the end of repositories:

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

Step 2. Add the dependency

dependencies {
// Material Components for Android
implementation 'com.google.android.material:material:x.x.x'
implementation 'com.github.ImaginativeShohag:Oops-No-Internet:vx.x.x'
}

Replace x.x.x with the latest versions.

Note 0. Minimum SDK for this library is API 21 (Android 5.0 Lollipop).

Note 1. Your application have to use AndroidX to use this library.

Note 2. Your have to use *.MaterialComponents.* in you styles.

Step 3. Add to your code

To use the NoInternetDialog and/or NoInternetSnackbar, use the builder and initialize it in onResume() and finally destroy it in onPause().

// Kotlin
class MainActivity : AppCompatActivity() {

// No Internet Dialog
private var noInternetDialog: NoInternetDialog? = null

// No Internet Snackbar
private var noInternetSnackbar: NoInternetSnackbar? = null

// ...

override fun onResume() {
super.onResume()

// No Internet Dialog
noInternetDialog = NoInternetDialog.Builder(this)
.build()

// No Internet Snackbar
noInternetSnackbar =
NoInternetSnackbar.Builder(this, findViewById(android.R.id.content))
.build()
}

override fun onPause() {
super.onPause()

// No Internet Dialog
noInternetDialog?.destroy()

// No Internet Snackbar
noInternetSnackbar?.destroy()
}
}

The NoInternetDialog and/or NoInternetSnackbar will then automatically appear when no active Internet connection found and disappear otherwise.

For details implementation see the GitHub repository: https://github.com/ImaginativeShohag/Oops-No-Internet and sample project.

What’s next?

My next target is to add custom layout options for the dialog. Give me your valuable comments, suggestions or ideas about the library! 😎

Okey then…

Use it… clone it… fork it… give PRs and finally, give a star to the repository and share it if you like…