Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
public class MyNetworkConnectedReceiver extends BroadcastReceiver {
private Context _context;
@Override
public void onReceive(Context context, Intent intent) {
_context = context;
ConnectivityManager connectivityManager = ((ConnectivityManager) context
.getSystemService(Context.CONNECTIVITY_SERVICE));
NetworkInfo currentNetworkInfo = connectivityManager.getActiveNetworkInfo();
if (currentNetworkInfo != null && currentNetworkInfo.isConnected()) {
//do something when network connected.
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.