is Device Network Online - Android Network

Android examples for Network:Network Status

Description

is Device Network Online

Demo Code


//package com.java2s;
import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class Main {
    public static boolean isOnline(final Context context) {
        ConnectivityManager cm = (ConnectivityManager) context
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo netInfo = cm.getActiveNetworkInfo();
        return (netInfo != null) && netInfo.isConnectedOrConnecting();
    }//w ww  .ja v a  2 s.c  o m
}

Related Tutorials