Java tutorial
//package com.java2s; import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; public class Main { private static boolean isNetworkConnected(Context context, int typeMobile) { boolean ret = false; if (!isNetConnected(context)) { return ret; } ConnectivityManager connectManger = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connectManger.getNetworkInfo(typeMobile); if (networkInfo == null) { return ret; } return ret; } public static boolean isNetConnected(Context context) { boolean ret = false; ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); if (networkInfo == null) { return ret; } ret = networkInfo.isAvailable() & networkInfo.isConnected(); return ret; } }