0
点赞
收藏
分享

微信扫一扫

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 "";

}

}

举报

相关推荐

0 条评论