Java tutorial
//package com.java2s; import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; public class Main { private static boolean checkNetWork_b(Context context) { ConnectivityManager connectMgr = (ConnectivityManager) context .getSystemService(context.CONNECTIVITY_SERVICE); NetworkInfo mobNetInfo = connectMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); NetworkInfo wifiNetInfo = connectMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI); NetworkInfo mNetworkInfo = connectMgr.getActiveNetworkInfo(); boolean bmob = mobNetInfo.isConnected(); boolean bwifi = wifiNetInfo.isConnected(); if (!bmob && !bwifi) { // Log.i(TAG, "unconnect"); // unconnect network return false; } else { // connect network return true; } } }