Skip to content

Instantly share code, notes, and snippets.

@danilao
danilao / gist:4132844
Created November 22, 2012 20:37
Check network connection in Android
public boolean isOnline() {
ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo netInfo = cm.getActiveNetworkInfo();
if (netInfo != null && netInfo.isConnectedOrConnecting()) {
return true;
}
Toast .makeText ( this, "Please, check your network connection" , Toast.LENGTH_LONG ).show();
return false;
}
@danilao
danilao / gist:4016626
Created November 5, 2012 10:58
Retrieve final URL from facebook profile image
URL img_value = null;
try {
/* Public image url */
img_value = new URL( "http://graph.facebook.com/" + id + "/picture?type=large" );
/* For caching purposes we need to get an unique url, not the public */
URL img_value_new = new URL("http://graph.facebook.com/" + id + "/picture?type=large&redirect=false" );
/* Open the above url and get the final image profile URL */
// Add to the application descriptor file
MIDlet-Touch-Support: true
Navi-Key-Hidden: true
//For Nokia devices
Nokia-MIDlet-On-Screen-Keypad: no
@danilao
danilao / gist:342757
Created March 24, 2010 20:36
Nested searches
@users = User.find(:all, :joins => :books, :conditions => {:books => {:title => 'Peter Pan'}})