I searched several answer in stackoverflow but i could not find it so posting this question.
Below code opens the camera and when we take picture and select it using (tick mark) below second code get called but Uri selectedImage = data.getData(); shows as null, why? how to fix this issue so i get proper value for selectedImage!
When Camera option selected, this code executes
Uri uri = FileProvider.
getUriForFile(getContext(),
BuildConfig.APPLICATION_ID + ".provider",
new File(Environment.getExternalStorageDirectory(),
"tmp_avatar_" + String.valueOf(System.currentTimeMillis()) + ".jpg"));
Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
takePicture.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
takePicture.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, uri);
takePicture.putExtra("return-data", true);
Toast.makeText(getContext(), "CAMERA clicked", Toast.LENGTH_LONG).show();
someActivityResultLauncher.launch(takePicture);
And above code calls this
ActivityResultLauncher<Intent> someActivityResultLauncher = registerForActivityResult(
new ActivityResultContracts.StartActivityForResult(),
new ActivityResultCallback<ActivityResult>() {
@Override
public void onActivityResult(ActivityResult result) {
if (result.getResultCode() == Activity.RESULT_OK) {
// There are no request codes
Intent data = result.getData();
Uri selectedImage = data.getData(); //<----this is showing NULL, why?
uploadImageFile(selectedImage);
}
}
});