I am developing an app with functionality of taking image from camera or gallery. This is working fine in all the devices but not in OnePlus.
This is the code :
public File dispatchTakePictureIntent(Activity activity) {
File tempPhotoFile = null;
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (takePictureIntent.resolveActivity(activity.getPackageManager()) != null) {
try {
tempPhotoFile = Utils.createImageFile(activity);
} catch (Exception e) {
e.printStackTrace();
}
if (tempPhotoFile != null) {
Uri photoURI = FileProvider.getUriForFile(activity, Utils.getFileProvider(activity), tempPhotoFile);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
takePictureIntent.setClipData(ClipData.newRawUri("", photoURI));
takePictureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
activity.startActivityForResult(takePictureIntent, Constants.REQUEST_IMAGE_CAPTURE);
}
}
return tempPhotoFile;
}
Code in Utils :
public static File createImageFile(Context context) throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.ENGLISH).format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
// Save a file: path for use with ACTION_VIEW intents
return image;
}
Now the app is working fine in other devices. But in OnePlus when the camera opens and we click the image and the preview is shown, at that time in the logcat we see that the app is shown dead and its restarted and it opens on app home scree. when we go to the particular tab from where we open the camera app, we can see the state is saved and we land on the same page. How can we solve the issue?