Return if the device is on the internet - Android Hardware

Android examples for Hardware:Device Feature

Description

Return if the device is on the internet

Demo Code


//package com.java2s;
import android.content.Context;
import android.content.ContextWrapper;

import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class Main {
    /**/*from www.j a  v a2  s . c o m*/
     * Return if the device is on the internet
     * @param contextWrapper
     * @return
     */
    public static boolean isOnline(ContextWrapper contextWrapper) {
        ConnectivityManager cm = (ConnectivityManager) contextWrapper
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo netInfo = cm.getActiveNetworkInfo();
        return netInfo != null && netInfo.isConnected();
    }
}

Related Tutorials