android判断用户网络类型
public class NetTestActivity extends Activity {private static final int CMNET = 3;private static final int CMWAP = 2;private static final int WIFI = 1;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);getAPNType(this);}/** * 获取当前的网络状态 -1:没有网络 1:WIFI网络2:wap网络3:net网络 * * @param context * @return */public static int getAPNType(Context context) {int netType = -1;ConnectivityManager connMgr = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();if (networkInfo == null) {return netType;}int nType = networkInfo.getType();System.out.println("networkInfo.getExtraInfo() is "+ networkInfo.getExtraInfo());if (nType == ConnectivityManager.TYPE_MOBILE) {if (networkInfo.getExtraInfo().toLowerCase().equals("cmnet")) {netType = CMNET;} else {netType = CMWAP;}} else if (nType == ConnectivityManager.TYPE_WIFI) {netType = WIFI;}return netType;}}
?