Instead of blocking the main thread, you could introduce a screen to the users with a connection notification to let them know what's happening.
While showing a screen with the notification you could check for a connection using the
ConnectivityManager
Note that checking only a WIFI connection will not guarantee a data service. Network issues, server downtime, authorization, etc. could always occur.
Example of usage:
private boolean isNetworkAvailable() {
ConnectivityManager connectivityManager
= (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
return activeNetworkInfo != null && activeNetworkInfo.isConnected();
}
Also, don't forget to add the right permission:
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
You can find more about this on the Android Developer website:
Determining and Monitoring the Connectivity Status
Good luck.