You onActivityResult is very messy.
Try to write code something like this way.. Below tow method is define to capture image from camera and taking image from gallery respectively.
protected void captureFromCamera() {
// TODO Auto-generated method stub
Intent cameraIntent = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent,
UploadProfilePicActivity.REQ_CAMERA);
}
private void selectImageFromGallery() {
// TODO Auto-generated method stub
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,
getString(R.string.upload_profile_photo)),
UploadProfilePicActivity.REQ_GALLERY);
}
Now onActivityResult your code could be something like this..
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == UploadProfilePicActivity.REQ_GALLERY && data != null
&& data.getData() != null) {
Uri _uri = data.getData();
try {
Bitmap profileBmp = Media.getBitmap(getContentResolver(), _uri);
if (profileBmp != null) {
image.setImageBitmap(profileBmp);
}
} catch (OutOfMemoryError e) {
Utility.displayToast(context,
getString(R.string.err_large_image));
} catch (Exception e) {
}
} else if (requestCode == UploadProfilePicActivity.REQ_CAMERA
&& data != null) {
try {
Bitmap profileBmp = (Bitmap) data.getExtras().get("data");
if (profileBmp != null) {
image.setImageBitmap(profileBmp);
}
} catch (OutOfMemoryError e) {
Utility.displayToast(context,
getString(R.string.err_large_image));
} catch (Exception e) {
}
}
}
A better imnplementation of onActivityResult using the parameters i.e requestCode
and responseCode