intent.setType("image/*"); //The argument is an all-lower-case MIME type - in this case, any image format.
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, false); //This is false by default, but I felt that for code clarity it was better to be explicit: we only want one image
//"The resultCode will be RESULT_CANCELED if the activity explicitly returned that, didn't return any result, or crashed during its operation." (quote from https://developer.android.com/reference/android/app/Activity.html#onActivityResult(int,%20int,%20android.content.Intent) )
if (requestCode == CHOOSE_IMAGE) {
setBackgroundUri(data.getData());
}
}
}
public void setBackgroundUri(Uri uri) {
if (uri == null) {
return;
}
try {
//I don't like loading both full-sized and reduced-size copies of the image (the larger copy can use a lot of memory), but I couldn't find any other way to do this.