20 lines
574 B
Java
20 lines
574 B
Java
|
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;
|
||
|
}
|
||
|
}
|