0

I try to do if I do not have an internet connection, I use the local database, if I have access to the internet, I use the remote database and I save the data obtained in the local database, I try to validate verifying that they are active wi-fi or data in the cell phone, but you can not really determine if I have an internet connection, what can I do? If someone has an example or a repository, it would be great, thank you

Juan Dadky
  • 5
  • 1
  • 3

3 Answers3

0

You can try the following to determine availability of internet.

public boolean isInternetAvailable() {
try {
    final InetAddress address = InetAddress.getByName("www.google.com");
    return !address.equals(""); // if we find the address that means internet is working
} catch (UnknownHostException e) {
    // Log error
}
return false;

}

Vishal Arora
  • 2,524
  • 2
  • 11
  • 14
0

please refer to the following link to determine whether the internet is available or not:

Detect whether there is an Internet connection available on Android

0

Use BoundaryCallback

When local storage is a cache of network data, it's common to set up a streaming pipeline: Network data is paged into the database, database is paged into UI.

BoundaryCallback