I am working on online app. [Problem] when internet is down or not available it gives me error [Force close], I tried to handle using broadCast Receiver but not meet exact solution, looking for better solution.
public class MyBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(final Context context, final Intent intent) {
NetworkInfo info = intent
.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
if (null != info) {
String state = info.getState().toString();
if (state.equalsIgnoreCase("CONNECTED")) {
SplashScreen.isWiFiConnected = true;
Log.i("isWifiConnected", "=================TRUE");
} else {
SplashScreen.isWiFiConnected = false;
Log.i("isWifiConnected", "=================FALSE");
}
}
}
}
thanks.
call this method in your doInBackground() of asyntask, and onPostExecute() check isNetError value and as mentioned in other answer of adding permission
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />