2019-pracownia-programowani.../Lookify/app/src/main/java/com/example/lookifyv2/CheckInternet.java

20 lines
574 B
Java
Raw Normal View History

package com.example.lookifyv2;
import java.io.IOException;
public class CheckInternet {
//https://stackoverflow.com/a/27312494/12566206
public boolean isOnline() {
Runtime runtime = Runtime.getRuntime();
try {
Process ipProcess = runtime.exec("/system/bin/ping -c 1 8.8.8.8");
int exitValue = ipProcess.waitFor();
return (exitValue == 0);
}
catch (IOException e) { e.printStackTrace(); }
catch (InterruptedException e) { e.printStackTrace(); }
return false;
}
}