I want to sync my embedded database with my server when the internet is up again, there is a clean way to do it instead of checking the internet connection with a while(true) in a background thread?
Now I'm checking Internet connetion manually this way:
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;
}
I solved follwing this: Internet listener Android example