I'm trying to use MediaStore.ACTION_IMAGE_CAPTURE
intent to take a profile photo.
The code that starts the intent:
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File myPicture = new File(OfflineApp.getAppContext().getFilesDir() + "/" + getResources().getString(R.string.contact_photos_dir), getResources().getString(R.string.my_photo_file_name));
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(myPicture));
startActivityForResult(cameraIntent, REQUEST_CODE_TAKE_PHOTO);
And the onActivityResult part:
case REQUEST_CODE_TAKE_PHOTO:
if (resultCode == RESULT_OK) {
String path = new File(OfflineApp.getAppContext().getFilesDir() + "/" + getResources().getString(R.string.contact_photos_dir), getResources().getString(R.string.my_photo_file_name)).getAbsolutePath();
ContactManager.getInstance().updateMyImage(path);
}
break;
However, the result code is always RESULT_CANCELED
, only if I provide MediaStore.EXTRA_OUTPUT
, even if the file doesn't exist.
Since Camera Intent is launching the Camera app, it has no access to my apps file folder. Fixed it by passing an external folder file and copying it to my local folder.