All Projects → muddassir235 → connection_checker

muddassir235 / connection_checker

Licence: MIT License
Android library for checking the internet connectivity of a device.

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to connection checker

Is Reachable
Check if servers are reachable
Stars: ✭ 249 (+857.69%)
Mutual labels:  detect, internet, ping
Connectivity
🌐 Makes Internet connectivity detection more robust by detecting Wi-Fi networks without Internet access.
Stars: ✭ 1,476 (+5576.92%)
Mutual labels:  internet-connection, wifi-network, internet-connectivity
Is Online
Check if the internet connection is up
Stars: ✭ 894 (+3338.46%)
Mutual labels:  detect, internet, ping
python-valid8
Yet another validation lib ;). Provides tools for general-purpose variable validation, function inputs/outputs validation as well as class fields validation. All entry points raise consistent ValidationError including all contextual details, with dynamic inheritance of ValueError/TypeError as appropriate.
Stars: ✭ 24 (-7.69%)
Mutual labels:  checker, check
Franc
Natural language detection
Stars: ✭ 3,605 (+13765.38%)
Mutual labels:  detect, detection
Wasm Check
TypeScript / JavaScript library for detect WebAssembly features in node.js & browser
Stars: ✭ 30 (+15.38%)
Mutual labels:  detect, detection
Piracychecker
An Android library that prevents your app from being pirated / cracked using Google Play Licensing (LVL), APK signature protection and more. API 14+ required.
Stars: ✭ 1,359 (+5126.92%)
Mutual labels:  verify, gradle
direct-net-share
share internet via Wifi direct on Android
Stars: ✭ 36 (+38.46%)
Mutual labels:  internet, internet-connection
checkif.js
Javascript check library
Stars: ✭ 30 (+15.38%)
Mutual labels:  verify, check
wifisdk
Free WiFi Connect SDK
Stars: ✭ 28 (+7.69%)
Mutual labels:  internet, wifi-network
es-feature-detection
ECMAScript feature and API detection
Stars: ✭ 16 (-38.46%)
Mutual labels:  detect, check
react-health-check
Lightweight React hook for checking health of API services.
Stars: ✭ 28 (+7.69%)
Mutual labels:  detect, check
Forbidden Apis
Policeman's Forbidden API Checker
Stars: ✭ 216 (+730.77%)
Mutual labels:  gradle, checker
East icpr
Forked from argman/EAST for the ICPR MTWI 2018 CHALLENGE
Stars: ✭ 154 (+492.31%)
Mutual labels:  detect, detection
Fetch
The best file downloader library for Android
Stars: ✭ 1,124 (+4223.08%)
Mutual labels:  gradle, internet
Reactivenetwork
Android library listening network connection state and Internet connectivity with RxJava Observables
Stars: ✭ 2,484 (+9453.85%)
Mutual labels:  internet, internet-connection
cross connectivity
A Flutter plugin for handling Connectivity and REAL Connection state in the mobile, web and desktop platforms. Supports iOS, Android, Web, Windows, Linux and macOS.
Stars: ✭ 27 (+3.85%)
Mutual labels:  internet-connection, internet-connectivity
speed-cloudflare-cli
📈 Measure the speed and consistency of your internet connection using speed.cloudflare.com
Stars: ✭ 99 (+280.77%)
Mutual labels:  internet, ping
detect-browser-language
Detect browser language
Stars: ✭ 35 (+34.62%)
Mutual labels:  detect, detection
netcheck
A shell script to check and log when your internet connection goes down.
Stars: ✭ 138 (+430.77%)
Mutual labels:  internet-connection, ping

ConnectionChecker

Release

Android library for checking the internet connectivity of a device.

Used in https://play.google.com/store/apps/details?id=com.muddassirkhan.quran_android

Add Dependencies

Add the following in your project level build.gradle

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

and the following in your app level build.gradle

dependencies {
    implementation 'com.github.muddassir235:connection_checker:1.7'
}

Use The Library

Use this library in one of the following three ways,

1. Using a method and an interface

checkConnection(this) // this: lifecycleOwner (e.g. Activity) which has implemented ConnectivityListener

By default it will ping https://www.google.com. The user can set the url to ping.

checkConnection(this, "https://www.site.url")

By default the least required lifecycle state is Lifecycle.State.RESUMED. The user can set it to what they require.

checkConnection(this, "https://www.site.url", Lifecycle.State.STARTED)

Example in an Android Activity.

class MainActivity : AppCompatActivity(), ConnectivityListener {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        checkConnection(this)
    }

    override fun onConnectionState(state: ConnectionState) {
        connection_status_tv.text = when (state) {
            ConnectionState.CONNECTED -> {
                "Connected"
            }
            ConnectionState.SLOW -> {
                "Slow Internet Connection"
            }
            else -> {
                "Disconnected"
            }
        }
    }
}

2. [Or] Using a method and a lambda callback

// this is a lifecycleOwner (e.g. Activity or ViewLifecycleOwner)
checkConnection(this) { connectionState ->
    // Your logic here
}

By default it will ping https://www.google.com. The user can set the url to ping.

checkConnection(this, "https://www.site.url") { connectionState ->
    // Your logic here
}

By default the least required lifecycle state is Lifecycle.State.RESUMED. The user can set it to what they require.

checkConnection(this, "https://www.site.url", Lifecycle.State.STARTED) { connectionState ->
    // Your logic here
}

Example in an Android Activity.

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        checkConnection(this) { connectionState ->
            connection_status_tv.text = when(connectionState) {
                ConnectionState.CONNECTED -> {
                    "Connected"
                }
                ConnectionState.SLOW -> {
                    "Slow Internet Connection"
                }
                else -> {
                    "Disconnected"
                }
            }
        }
    }
}

3. [Or] Using a class object and an interface

val connectionChecker = ConnectionChecker(this)

By default it will ping https://www.google.com. The user can set the url to ping.

val connectionChecker = ConnectionChecker(this, "https://www.site.url")

By default the least required lifecycle state is Lifecycle.State.RESUMED. The user can set it to what they require.

val connectionChecker = ConnectionChecker(this, "https://www.site.url", Lifecycle.State.STARTED)

Add connectivity listener

connectionChecker.connectivityListener = object: ConnectivityListener {
    override fun onConnectionState(state: ConnectionState) {
        // Your logic goes here
    }
}

Example in an Android Activity.

class MainActivity : AppCompatActivity(), ConnectivityListener {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val connectionChecker = ConnectionChecker(this, lifecycle)
        connectionChecker.connectivityListener = this
    }

    override fun onConnectionState(state: ConnectionState) {
        connection_status_tv.text = when (state) {
            ConnectionState.CONNECTED -> {
                "Connected"
            }
            ConnectionState.SLOW -> {
                "Slow Internet Connection"
            }
            else -> {
                "Disconnected"
            }
        }
    }
}

Uses

Apps by Muddassir Ahmed:

Muddassir Ahmed Links:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].