Android examples for Network:Network Status
get Network Type
//package com.java2s; import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.net.NetworkInfo.State; public class Main { private static Context mContext; public static String getNetworkType() { ConnectivityManager connManager = (ConnectivityManager) mContext .getSystemService(Context.CONNECTIVITY_SERVICE); if (connManager != null) { NetworkInfo wifi = connManager .getNetworkInfo(ConnectivityManager.TYPE_WIFI); // wifi NetworkInfo gprs = connManager .getNetworkInfo(ConnectivityManager.TYPE_MOBILE); // gprs if (wifi != null && wifi.getState() == State.CONNECTED) { return "wifi"; } else if (gprs != null && gprs.getState() == State.CONNECTED) { return "gprs"; }//from w ww .j av a 2s .c o m } return "none"; } }