Java tutorial
//package com.java2s; //License from project: Apache License import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; public class Main { public static boolean isMobileConnected(Context context) { NetworkInfo net = getConnManager(context).getActiveNetworkInfo(); return net != null && net.getType() == 0 && net.isConnected(); } public static ConnectivityManager getConnManager(Context context) { return (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); } public static boolean isConnected(Context context) { NetworkInfo net = getConnManager(context).getActiveNetworkInfo(); return net != null && net.isConnected(); } }