返回顶部

收藏

Android 判断当前网络服务

更多

判断当前网络是否是3G网络 java public static boolean is3G(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo(); if (activeNetInfo != null &amp;&amp; activeNetInfo.getType() == ConnectivityManager.TYPE_MOBILE) { return true; } return false; }判断当前网络是否是wifi网络 java public static boolean isWifi(Context context) { ConnectivityManager connectivityManager = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetInfo = connectivityManager.getActiveNetworkInfo(); if (activeNetInfo != null &amp;&amp; activeNetInfo.getType() == ConnectivityManager.TYPE_WIFI) { return true; } return false; }判断是否有网络连接 java public static boolean isConnect(Context context) { ConnectivityManager connectivity = (ConnectivityManager) context .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetInfo = connectivity.getActiveNetworkInfo(); if (activeNetInfo != null &amp;&amp; activeNetInfo.isConnected()) { <span style="white-space:pre"> </span>if (activeNetInfo.getState() == NetworkInfo.State.CONNECTED) { return true; } } return false; }

标签:java

收藏

0人收藏

支持

0

反对

0

发表评论