ネットワークが使用可能かどうかを確認
899 ワード
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;
}