on capturing image from camera in lollipop and higher versions getting the result data null on onActivityResult.
launchCamera();
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
((MyWebViewActivity) context).fileUri = CommonUtils.getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, ((MyWebViewActivity) context).fileUri);
((MyWebViewActivity) context).startActivityForResult(intent, CAMERA_CAPTURE_IMAGE_REQUEST_CODE);
@Override
onActivityResult(int requestCode, int resultCode, Intent data);
if (requestCode == CAMERA_CAPTURE_IMAGE_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
if(fileUri!=null){
file_path = fileUri.getPath();
System.out.println("file-path---=" + file_path);
}else{
Toast.makeText(this, "Please try again", Toast.LENGTH_LONG).show();
}
if(!CommonUtils.isEmpty(file_path)){
}
} else if (resultCode == RESULT_CANCELED) {
// "User cancelled image capture",
} else {
// failed to capture image
}
}
getOutputMediaFileUri()
File file = getOutputMediaFile(type);
if (file != null) {
return Uri.fromFile(file);
}
return null;
getOutputMediaFile()
// External sdcard location
File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "My Images");
// Create the storage directory if it does not exist
if (!mediaStorageDir.exists()) {
if (!mediaStorageDir.mkdirs()) {
return null;
}
}
// Create a media file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.getDefault()).format(new Date());
File mediaFile;
System.out.println("mediaStorageDir==" + mediaStorageDir);
if (type == MEDIA_TYPE_IMAGE) {
mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + ".png");
} else if (type == MEDIA_TYPE_VIDEO) {
mediaFile = new File(mediaStorageDir.getPath() + File.separator + "VID_" + timeStamp + ".mp4");
} else {
return null;
}
return mediaFile;