【发布时间】:2017-07-24 11:14:18
【问题描述】:
这是我的相机意图。
File file = getExternalFilesDir(Environment.DIRECTORY_DCIM);
file.mkdirs();
File output = new File(file, "profile_image");
if (output.exists()) {
output.delete();
}
Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, output);
startActivityForResult(captureIntent, PublicValues.IMAGE_FROM_CAMERA);
在活动结果中
if (requestCode == PublicValues.IMAGE_FROM_CAMERA) {
if (mPhotoUri != null) {
performCrop(mPhotoUri);
} else {
pictureUri = data.getData();
performCrop(pictureUri);
}
和裁剪意图
Intent cropIntent = new Intent("com.android.camera.action.CROP");
cropIntent.setDataAndType(picUri, "image/*");
cropIntent.putExtra("crop", "true"); // set crop properties
cropIntent.putExtra("aspectX", 1); // indicate aspect of desired crop(ratio)
cropIntent.putExtra("aspectY", 1);
cropIntent.putExtra("return-data", true); // retrieve data on return
cropIntent.putExtra("outputX", profileImage.getWidth()); // indicate output X and Y
cropIntent.putExtra("outputY", profileImage.getHeight());
startActivityForResult(cropIntent, PublicValues.IMAGE_CROP);
它在 API 19 设备上运行良好,但在 Marshmallow 设备中崩溃。
崩溃报告是这样的:-
Caused by android.os.FileUriExposedException: file:///storage/emulated/0/WhatsApp/Media/WhatsApp Images/IMG-20170721-WA0014.jpg exposed beyond app through Intent.getData()
android.os.StrictMode.onFileUriExposed (StrictMode.java:1813)
android.net.Uri.checkFileUriExposed (Uri.java:2360)
android.content.Intent.prepareToLeaveProcess (Intent.java:8981)
android.content.Intent.prepareToLeaveProcess (Intent.java:8942)
android.app.Instrumentation.execStartActivity (Instrumentation.java:1583)
android.app.Activity.startActivityForResult (Activity.java:4228)
android.support.v4.app.BaseFragmentActivityJB.startActivityForResult (BaseFragmentActivityJB.java:50)
android.support.v4.app.FragmentActivity.startActivityForResult (FragmentActivity.java:79)
【问题讨论】:
-
能贴出错误日志吗?
-
@AjilO。查看我的编辑
-
所有权限都授予您的应用,对吗??
-
@GaganDeep yup.CAMERA,读写外部存储
-
Android 没有
CROPIntent。有很多image cropping libraries available for Android。请使用一个。