- 有直接的api来分辨:
- ConnectivityManager connectivityManager= (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
- try{
- ConnectivityManager connectivityManager= (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
- if(connectivityManager!= null){
- NetworkInfo networkInfo= connectivityManager.getActiveNetworkInfo();
- if(networkInfo!= null){
- netType = networkInfo.getType();
- Log.d("Log","connetion is available");
- }else{
- Log.d("Log","connetion is not available");
- return networkStatus;
- }
- // if(networkInfo.isAvailable()){ // Old one
-
- if(networkInfo.isAvailable()&& networkInfo.isConnected()){// New change added here
- if(netType== ConnectivityManager.TYPE_WIFI)
- {}
- elseif(netType== ConnectivityManager.TYPE_MOBILE)
- {}
- }
- }
- }catch(Exception e){
- Log.d("Log","checkNetworkConnection" + e.toString());
- return networkStatus;
- if(networkInfo.isAvailable()&& networkInfo.isConnected()){// New change added here
android 如何分辨移动wap网络,3G网络,WIFI网络
最新推荐文章于 2023-05-05 11:07:40 发布