WEB开发网
开发学院手机开发Android 开发 android 实现检查网络是否可用 阅读

android 实现检查网络是否可用

 2010-11-05 00:56:44 来源:WEB开发网   
核心提示:Java代码public static boolean isNetworkConnected(Context context) {ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SE

Java代码

public static boolean isNetworkConnected(Context context) {

ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

NetworkInfo network = cm.getActiveNetworkInfo();

if (network != null) {

return network.isAvailable();

}

return false;

}

public static boolean isNetworkConnected(Context context) {

ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);

NetworkInfo network = cm.getActiveNetworkInfo();

if (network != null) {

return network.isAvailable();

}

return false;

}

< uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>< !-- 检查网络 -->

Tags:android 实现 检查

编辑录入:coldstar [复制链接] [打 印]
赞助商链接