Here you can find the source of isDeviceOnline(Activity activity)
Parameter | Description |
---|---|
activity | a parameter |
public static boolean isDeviceOnline(Activity activity)
//package com.java2s; import android.app.Activity; import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; public class Main { /**//from w w w . j a v a2 s .c o m * Iterates all network infos and returns true if one of them is available for * sending data. * @param activity * @return true if a network connection exists. Otherwise, flase is returned. * @author Jason Myerscough */ public static boolean isDeviceOnline(Activity activity) { ConnectivityManager cm = (ConnectivityManager) activity .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo[] netInfo = cm.getAllNetworkInfo(); if (netInfo != null) { for (int i = 0; i < netInfo.length; i++) { if (netInfo[i].isConnected()) return true; } } return false; } }