//获取连接管理
ConnectivityManager manager=(ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
//获取当前网络信息对象
NetworkInfo info=manager.getActiveNetworkInfo();
if(info!=null&&info.isAvailable()&&info.isConnected()){
//网络是否连接
int type=info.getType();
if(type==ConnectivityManager.TYPE_WIFI){
//WIFI网络
Toast.makeText(this,"WIFI",0).show();
}else if(type==ConnectivityManager.TYPE_MOBILE){
Toast.makeText(this,"手机流量",0).show();
}
}else{
Toast.makeText(MainActivity.this,"网络不可用",0).show();
}
ConnectivityManager manager=(ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
//获取当前网络信息对象
NetworkInfo info=manager.getActiveNetworkInfo();
if(info!=null&&info.isAvailable()&&info.isConnected()){
//网络是否连接
int type=info.getType();
if(type==ConnectivityManager.TYPE_WIFI){
//WIFI网络
Toast.makeText(this,"WIFI",0).show();
}else if(type==ConnectivityManager.TYPE_MOBILE){
Toast.makeText(this,"手机流量",0).show();
}
}else{
Toast.makeText(MainActivity.this,"网络不可用",0).show();
}