Image is crop and see successfully in List in marshmallow and above but not working below marshmallow. I think if we pick google photo for crop than it is working in other scenario its nont working.
Also in my situation runtime permission is already provided.
Code to click image from camera
Uri fileUri;
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
File file = new File(getExternalCacheDir(), String.valueOf(System.currentTimeMillis()) + ".jpg");
fileUri = Uri.fromFile(file);
intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
startActivityForResult(intent, 501);
@Override
protected void onActivityResult(int requestCode, int resultCode, final Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case 501:
isFromOneActivityToAnother = true;
ImageCropFunction();
//startCropImageActivity(fileUri);
break;
case 502:
uriImageListForServer.add(getImageContentUri(getApplicationContext(), new File((fileUri + "").substring(7, (fileUri + "").length()))));
break;
}
}
public void ImageCropFunction() {
try {
isFromOneActivityToAnother = true;
Intent CropIntent = new Intent("com.android.camera.action.CROP");
CropIntent.setDataAndType(fileUri, "image/*");
CropIntent.putExtra("crop", "true");
CropIntent.putExtra("outputX", 2048);
CropIntent.putExtra("outputY", 2048);
CropIntent.putExtra("scaleUpIfNeeded", true);
CropIntent.putExtra("return-data", true);
startActivityForResult(CropIntent, 502);
} catch (ActivityNotFoundException e) {
}
}
public static Uri getImageContentUri(Context context, File imageFile) {
String filePath = imageFile.getAbsolutePath();
Cursor cursor = context.getContentResolver().query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
new String[]{MediaStore.Images.Media._ID},
MediaStore.Images.Media.DATA + "=? ",
new String[]{filePath}, null);
if (cursor != null && cursor.moveToFirst()) {
int id = cursor.getInt(cursor.getColumnIndex(MediaStore.MediaColumns._ID));
cursor.close();
return Uri.withAppendedPath(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "" + id);
} else {
if (imageFile.exists()) {
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.DATA, filePath);
return context.getContentResolver().insert(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
} else {
return null;
}
}
}