android获取NetworkMode

public String getNetworkMode(Context context) {
ConnectivityManager conMan = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);


// mobile 3G Data Network


State mobile = State.UNKNOWN;
try {
mobile = conMan.getNetworkInfo(ConnectivityManager.TYPE_MOBILE)
.getState();
} catch (Exception e) {
}


// wifi
State wifi = State.UNKNOWN;
try {
wifi = conMan.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
.getState();
} catch (Exception e) {
}


if (wifi == State.CONNECTED) {
return "wifi";
} else if (mobile == State.CONNECTED) {
return "mobile";
} else {
return "";
}
}

你可能感兴趣的:(exception,android,String,service,mobile)