I am using CameraX API to take pictures in my android app, save them and then display them from their path. With the previous version alpha-09
I was able to do so with onImageSaved(File file)
. However with the alpha-10
I have to use onImageSaved(OutputFileResults outputFileResults)
and then get the path from the uri
retrieved by the outputFileResults
. But the Uri I get is always wrong. For instance when my image is saved at: "/external/images/media/1581680878237.jpg"
I get the uri's path: "/external/images/media/113758"
.
Here is my code:
ContentValues contentValues = new ContentValues();
contentValues.put(MediaStore.MediaColumns.DISPLAY_NAME, "NEW_IMAGE");
contentValues.put(MediaStore.MediaColumns.MIME_TYPE, "image/jpg");
ImageCapture.OutputFileOptions outputFileOptions = new ImageCapture.OutputFileOptions.Builder(
activity.getContentResolver(),
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
contentValues).build();
imageCapture.takePicture(outputFileOptions, Runnable::run, new ImageCapture.OnImageSavedCallback() {
@Override
public void onImageSaved(@NonNull ImageCapture.OutputFileResults outputFileResults) {
Uri uri = outputFileResults.getSavedUri();
if(uri != null){
System.out.println("URI PATH" + uri.getPath());
System.out.println("URI PATH" + uri.toString());
activity.runOnUiThread(cameraProvider::unbindAll);
galleryAddPic(uri);
Bundle params = new Bundle();
params.putString("FILE_PATH", uri.getPath());
Navigation.findNavController(root).navigate(R.id.navigation_edit_image, params);
}
}
@Override
public void onError(@NonNull ImageCaptureException exception) {
exception.printStackTrace();
}
});