Skip to content

Instantly share code, notes, and snippets.

View PasanBhanu's full-sized avatar

Pasan Bhanu Guruge PasanBhanu

View GitHub Profile
@mikeschinkel
mikeschinkel / functions.php
Created June 5, 2016 20:36
Example of how to use WordPress' wp_localize_script() script to provide number of page children to a jQuery script
<?php
// Your other your-theme/functions.php code goes here
add_action( 'wp_enqueue_scripts', 'yoursite_enqueue_scripts' );
function yoursite_enqueue_scripts() {
global $post;
if ( ! empty( $post ) && is_page( $post ) ) {
wp_enqueue_script( 'yoursite-js', get_stylesheet_directory_uri() . '/js/yoursite.js');
@PasanBhanu
PasanBhanu / CheckNetwork.java
Last active July 25, 2023 13:28
Check Internet Connection in Android (API Level 29) Using Network Callback
/*
You need to call the below method once. It register the callback and fire it when there is a change in network state.
Here I used a Global Static Variable, So I can use it to access the network state in anyware of the application.
*/
// You need to pass the context when creating the class
public CheckNetwork(Context context) {
this.context = context;
}
@Abhinav1217
Abhinav1217 / CheckNetwork.java
Last active November 11, 2022 05:02
Network Test on API 29 - Java
package com.example.simplenetwork;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.LinkProperties;
import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.NetworkRequest;
import android.util.Log;
@GokhanArik
GokhanArik / NetworkStateManager.kt
Created March 12, 2020 03:11
Check Internet Connection in Android 21+
package manager
import android.content.Context
import android.net.ConnectivityManager
import android.net.Network
import android.net.NetworkCapabilities
import android.net.NetworkRequest
import android.os.Build
import android.util.Log
import com.jakewharton.rxrelay2.BehaviorRelay
@iRYO400
iRYO400 / ConnectivityMonitor.kt
Created April 30, 2020 09:41
Check Internet Connection [API21+][API29+ supported] Lifecycle aware
import android.content.Context
import android.content.Context.CONNECTIVITY_SERVICE
import android.net.ConnectivityManager
import android.net.Network
import android.net.NetworkCapabilities
import android.net.NetworkRequest
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.OnLifecycleEvent