图像被裁剪并在棉花糖及以上的列表中成功查看,但在棉花糖下方无法正常工作。我认为如果我们选择谷歌照片进行裁剪,而不是在其他情况下工作它不起作用。
同样在我的情况下,已经提供了运行时权限。
从相机单击图像的代码
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;
}
}
}