Java tutorial
//package com.java2s; import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.net.NetworkInfo.State; import android.telephony.TelephonyManager; public class Main { public static String getPhoneNetworkType(TelephonyManager tm) { String networkType = "Unknown"; switch (tm.getNetworkType()) { case TelephonyManager.NETWORK_TYPE_1xRTT: networkType = "1xRTT:"; break; case TelephonyManager.NETWORK_TYPE_CDMA: networkType = "CDMA:"; break; case TelephonyManager.NETWORK_TYPE_EDGE: networkType = "EDGE:"; break; case TelephonyManager.NETWORK_TYPE_EVDO_0: networkType = "EVDO_0:"; break; case TelephonyManager.NETWORK_TYPE_EVDO_A: networkType = "EVDO_A:"; break; case TelephonyManager.NETWORK_TYPE_GPRS: networkType = "GPRS:"; break; case TelephonyManager.NETWORK_TYPE_HSDPA: networkType = "HSDPA:"; break; case TelephonyManager.NETWORK_TYPE_HSPA: networkType = "HSPA:"; break; case TelephonyManager.NETWORK_TYPE_HSUPA: networkType = "HSUPA:"; break; case TelephonyManager.NETWORK_TYPE_UMTS: networkType = "UMTS:"; break; case TelephonyManager.NETWORK_TYPE_UNKNOWN: networkType = "UNKNOWN:"; break; default: break; } return networkType + tm.getNetworkType(); } public static int getNetWorkType(Context context) { // showLog("getNetWorkType"); ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo(); if (null == networkInfo || !networkInfo.isAvailable()) { return 1; } if (State.CONNECTED == connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState()) { return 2; } if (State.CONNECTED == connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState()) { return 3; } return 4; } }