Reputation: 4064
I am facing a very strange issue. After clicking a picture from camera activity , a confirmation page appears with three options (icons) - OK , Retake and Cancel. The Retake and Cancel buttons are working fine but after clicking on OK button - nothing happens.Its not returning back to my activity. I have seen similar posts but none of them worked for me.I have given all the permission read write and camera.Below are some observations i made while dealing with the issue.
1.On Android 5.0.1 - LENEVO YOGA TAB 3 , Same Code , Ok button working fine.
2.On Android 6.0 - LENEVO YOGA TAB 3 , Same Code , Ok button not working (permissions added read , write and camera).
3.On Android 6.0 - LeEco 2 , Same Code , has NO Ok button , so is returning back to activity after capture - working fine (permissions added read , write and camera).
Its how i am opening my camera activity
public final static String PRE_CAMERA_FILE_NAME = "my_image";
public final static String FILE_DIRECTORY =
(Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState()) ?
Environment.getExternalStorageDirectory().getAbsolutePath() :
Environment.getDataDirectory()) + File.separator + "Images";
private void openCamera() {
Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
File mCameraFile = new File(FILE_DIRECTORY, String.valueOf(PRE_CAMERA_FILE_NAME + System.currentTimeMillis()) + ".jpg");
if(!mCameraFile.exists()){
mCameraFile.mkdirs();
}
System.out.println("Path:=" + mCameraFile.getAbsolutePath());
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
mCameraFileUri = FileProvider.getUriForFile(getContext(),
BuildConfig.APPLICATION_ID + ".provider", mCameraFile);
} else {
mCameraFileUri = Uri.fromFile(mCameraFile);
}
cameraIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, mCameraFileUri);
cameraIntent.putExtra("return-data", true);
getActivity().startActivityForResult(cameraIntent, REQUEST_TYPE_CAMERA);
}
OnActivityResult :
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (mOnFileChooseListener != null && resultCode == Activity.RESULT_OK) {
String path = "";
if (requestCode == REQUEST_TYPE_CAMERA) {
path = mCameraFileUri.getPath();
} else if (requestCode == REQUEST_TYPE_UPLOAD_PDF_OR_PHOTO && data != null) {
path = FileUtils.getFilePath(getContext(), data.getData());
}
mOnFileChooseListener.onFileSelected(path);
}
}
Permissions added .
[]
Can anyone please answer why this is happening ? Thanks in advance .
Upvotes: 1
Views: 977
Reputation: 321
I have same issue.
In my case, the save path was not correct. I changed sameFile.mkdirs()
on sameFile.getParentFile().mkdirs()
.
In your case mCameraFile.mkdirs()
сreates a directory with the file name.
My work code
File file = new File(getContext().getExternalFilesDir(Environment.DIRECTORY_PICTURES)
+ File.separator
+ screenState.catalogKey,
idImg.toString());
if (file.getParentFile().exists() || file.getParentFile().mkdirs()) {
mOutputFileUri = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, mOutputFileUri);
startActivityForResult(intent, ConstantManager.I_CAMERA_RESULT);
}
Upvotes: 1