Skip to content

Instantly share code, notes, and snippets.

@ArcherN9
Last active January 19, 2016 13:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ArcherN9/076f77fc123a986e22d0 to your computer and use it in GitHub Desktop.
Save ArcherN9/076f77fc123a986e22d0 to your computer and use it in GitHub Desktop.
@Override
protected void onResume() {
super.onResume();
//Register broadcast receiver to receive changes in connectivity
registerReceiver(brConnectivityChangeReceiver, new IntentFilter(
"android.net.conn.CONNECTIVITY_CHANGE" //Ideally, put this in the strings.xml file
));
}
private BroadcastReceiver brConnectivityChangeReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
//Get reference to the ConnectivityManager to retrieve network info object
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
//Get Network Info to access current connection type
NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
//Check if connected internet type is WiFi or not
if (networkInfo != null && networkInfo.getType() == ConnectivityManager.TYPE_WIFI)
ImageLoader.getInstance().displayImage(url, imageView, imageLoadingListener); //Attempt to load image again
else
Log.i(TAG, "Don't have Wifi Connection"); //Do nothing here since the user has already been prompted once to turn on wifi
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment