Reputation: 4698
I am opening default camera app to capture image in my application but not getting captured image uri. Below is my code -
Code for open camera -
initTmpUris();
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, capturedImageUri);
intent.putExtra("return-data", true);
Code for create image path to store -
private void initTmpUris() {
File proejctDirectory = new File(CameraUtil.FOLDER_PATH + File.separator + CameraUtil.FOLDER_NAME);
if (!proejctDirectory.exists()) {
proejctDirectory.mkdir();
}
File tempDirectory = new File(proejctDirectory, "temp");
if (!tempDirectory.exists()) {
tempDirectory.mkdir();
} else {
// delete all old files
for (File file : tempDirectory.listFiles()) {
if (file.getName().startsWith("tmp_")
|| file.getName().startsWith("croped_")) {
}
}
}
capturedImageUri = Uri.fromFile(new File(tempDirectory, "tmp_"
+ String.valueOf(System.currentTimeMillis()) + ".jpg"));
File extraOutputFile = new File(tempDirectory, "croped_"
+ String.valueOf(System.currentTimeMillis()) + ".jpg");
extraOutputFile.setWritable(true);
cropImageUri = Uri.fromFile(extraOutputFile);
}
and code in onActivityResult -
case REQ_CODE_PICK_FROM_CAMERA_WITHOUT_CROP: {
if (resultCode == RESULT_OK) {
if(null!=capturedImageUri) {
String imagePath = capturedImageUri.getPath();
File file = new File(imagePath);
onSingleImageSelected(reqCodeStarter, file, imagePath,
get_Picture_bitmap(file));
}
} else {
onMediaPickCanceled(reqCodeStarter,
REQ_CODE_PICK_FROM_CAMERA_WITHOUT_CROP);
}
}
break;
i am getting capturedImageUri in samsung s7 device, in other devices its return url of captured image.
Upvotes: 0
Views: 619
Reputation: 560
Add this code to your activity
tag inside your Manifest
file.
android:configChanges="orientation|keyboardHidden|screenSize"
It will not let your current activity to destory and re-create so you will get the result.
Upvotes: 2