Reputation: 5962
I want to know how I can make my app work in offline when user lost the network connectivity.
I need to post data to the server using JSON post method when the user is not connected with wifi or mobile data.
I am using following code to detect the network state using broadcast receiver and don't know how to proceed after this.
Please assist me to proceed further.
public class UpdateReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
ConnectivityManager connectivityManager = (ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetInfo = connectivityManager
.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
boolean isConnected = activeNetInfo != null
&& activeNetInfo.isConnectedOrConnecting();
if (isConnected) {
Log.e("NET", "connected" + isConnected);
} else {
Log.e("NET", "not connected to internet" + isConnected);
}
}
}
Upvotes: 1
Views: 1291