当我裁剪图像时,应用程序在Android 7.0中崩溃了。
例外: 02-06 12:40:53.717 5671-5685 / com.tribyte.iTutor2 E / DatabaseUtils:为包裹写例外 java.lang.SecurityException:Permission Denial:写android.support.v4.content.FileProvider uri content://com.tribyte.iTutor2.provider/external_files/Android/data/com.tribyte.iTutor2/files/Application/sites/来自pid = 6784的default /files/askexpertimages/325590_user1aipmt@gmail.com_1486365038955_crop.png,uid = 10105要求导出提供程序,或者grantUriPermission() 在android.content.ContentProvider.enforceWritePermissionInner(ContentProvider.java:682) 在android.content.ContentProvider $ Transport.enforceWritePermission(ContentProvider.java:497) 在android.content.ContentProvider $ Transport.enforceFilePermission(ContentProvider.java:469) 在android.content.ContentProvider $ Transport.openAssetFile(ContentProvider.java:384) 在android.content.ContentProviderNative.onTransact(ContentProviderNative.java:262) 在android.os.Binder.execTransact(Binder.java:565)
示例代码:
private void performCrop()
{
try
{
Intent intent = new Intent("com.android.camera.action.CROP");
List<ResolveInfo> resInfoList = this.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
for (ResolveInfo resolveInfo : resInfoList) {
String packageName = resolveInfo.activityInfo.packageName;
this.grantUriPermission(packageName, temppicUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
}
String extension = android.webkit.MimeTypeMap.getFileExtensionFromUrl(picUri.toString());
String mimetype = android.webkit.MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
intent.setDataAndType(picUri,mimetype);
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.putExtra("crop", "true");
intent.putExtra(MediaStore.EXTRA_OUTPUT, temppicUri);
intent.putExtra("outputX", 512);
intent.putExtra("outputY", 512);
intent.putExtra("aspectX", 0);
intent.putExtra("aspectY", 0);
//start the activity - we handle returning in onActivityResult
if (intent.resolveActivity(getPackageManager()) != null)
{
intent.putExtra("return-data", true);
startActivityForResult(intent, PIC_CROP);
}
}
catch(ActivityNotFoundException anfe)
{
//display an error message
String errorMessage = "Whoops - your device doesn't support the crop action!";
Toast toast = Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT);
toast.show();
}
}
答案 0 :(得分:-1)
在我有限的经验中,我认为它是由OOM引起的。代码如下,
intent.putExtra("outputX", 512);
intent.putExtra("outputY", 512);
在更高质量的设备中,512 * 512的尺寸太大,屏幕分辨率更高。如果图像很大,您可以缩小图像的大小。