本文主要是介绍android 处理网络状态——无网,2g,3g,wifi,ethernet,other,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
今天在一位很牛逼的学长的博客里面看到了这段代码后,很是激动啊,于是就“偷”了过来,嘿嘿。。。。为自己也为更多需要它的程序媛
直接上代码:
public class GetNetWorkStateActor extends FusionActor {@Override
public boolean processFusionMessage(FusionMessage msg) {
// TODO Auto-generated method stub
msg.setResponseData(checkNet());
return false;
}private int checkNet() {
// TODO Auto-generated method stub
ConnectivityManager connectivityManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo mobNetInfoActivity = connectivityManager
.getActiveNetworkInfo();
int netFlag = 0;
if (mobNetInfoActivity != null) {switch (mobNetInfoActivity.getType()) {
case ConnectivityManager.TYPE_ETHERNET:
// ethernet
netFlag = 1;
break;
case ConnectivityManager.TYPE_WIFI:
// wifi
netFlag = 2;
break;
case ConnectivityManager.TYPE_MOBILE:
// gprs
if(isFastMobileNetwork(context)){
//2g
netFlag = 3;
}else{
//3g
netFlag
这篇关于android 处理网络状态——无网,2g,3g,wifi,ethernet,other的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!