UPDATE:
I have restarted my device, and it works now. Like a magic!!
ORIGINAL QUESTION:
I have read many answers for my question, but i still can't get a solution for my problem:
I had 1 fragment that opened an intent for capturing a photo and in the fragment I had the method OnActivityResults and all worked fine.
Now, I added 2nd fragment that also calls an intent with the same code (but different request code). I'm not sure that this cause the problem, but now, when I push the "V" that approve the captured photo, I'm getting back to different fragment and the OnActivityResults method isn't called.
In the fragment:
private static final int REQUEST_TAKE_PHOTO_CODE = 11;
private static final int REQUEST_ATTACH_PHOTO_CODE = 22;
takePhotoButton = (ImageButton)rootView.findViewById(R.id.imageButtonTakePhoto);
takePhotoButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(MainActivity.deviceHasCamera){
Intent photoIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(photoIntent, REQUEST_TAKE_PHOTO_CODE );
}
else{
Toast.makeText(activity, "No camera detected", Toast.LENGTH_SHORT).show();
}
}
});
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d("EB", "onActivityResult CarAccident");
switch (requestCode) {
case REQUEST_TAKE_PHOTO_CODE:
//This case is when the user decide to Approve the captured photo
if (resultCode == Activity.RESULT_OK) {
photo = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(photo);
Log.d("EB", "BitMap = " + photo.toString());
}
break;
case REQUEST_ATTACH_PHOTO_CODE:
if (resultCode == Activity.RESULT_OK) {
Uri selectedImage = data.getData();
Log.d("EB", "Uri fata.getData() = " + data.getData().toString());
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = this.activity.getContentResolver().query(
selectedImage, filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String filePath = cursor.getString(columnIndex);
cursor.close();
photo = BitmapFactory.decodeFile(filePath);
//For the case that is Android 5.0 and the photo is on the server
// and not on the device
if (photo == null){
try {
photo = getBitmapFromUri(data.getData());
Log.d("EB", "photo = getBitmapFromUri(data.getData()) = " + photo.toString());
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(this.activity, FAILD_TO_ATTACH_PHOTO_MESSAGE,
Toast.LENGTH_SHORT).show();
}
}
//Set the photo to the imageView
imageView.setImageBitmap(photo);
Log.d("EB", "attached image = " + ((photo != null) ? photo.toString() : "NULL"));
}
break;
}
}
I tried to to write in the host Activity:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
}
But it's not working. Hope you can help. Thanks in advance!