检查网络是否可用

public static boolean isNetWorkDataAvailable(final Context context) {
    Runtime runtime = Runtime.getRuntime();
    try {
        Process pingProcess = runtime.exec("/system/bin/ping -c 1 www.baidu.com");
        int exitCode = pingProcess.waitFor();
        return (exitCode == 0);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}

你可能感兴趣的:(android)