好的一天。我有一個奇怪的問題,其中沒有任何示例在堆棧溢出工作。我打開一個畫廊,之後我重定向用戶裁剪intent.Important要提及的是,這隻發生在Android N,而不是設備下方。問題是,這種異常拋出作物完成後..我不知道是什麼原因,但實際上這裏是我如何開始作物的意圖。權限拒絕:寫作android.support.v4.content.FileProvider uri
Intent cropIntent = new Intent("com.android.camera.action.CROP");
cropIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
Uri outPutUri = FileProvider.getUriForFile(activity, activity.getApplicationContext().getPackageName() + ".provider", new File(output));
Uri photoURI = FileProvider.getUriForFile(activity, activity.getApplicationContext().getPackageName() + ".provider", new File(path));
activity.grantUriPermission("com.android.camera.action.CROP", outPutUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
activity.grantUriPermission("com.android.camera.action.CROP", photoURI, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
cropIntent.setDataAndType(photoURI, "image/*");
cropIntent.putExtra("crop", "true");
cropIntent.putExtra("aspectX", aspectX);
cropIntent.putExtra("aspectY", aspectY);
cropIntent.putExtra(MediaStore.EXTRA_OUTPUT, outPutUri);
activity.startActivityForResult(cropIntent, CROP_REQUEST);
茲授予開放的權限,已經添加了這些體現
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/provider_paths"/>
我已經嘗試了所有堆在流動答案的例子,對堆棧溢出沒有更多的問題與此方案並沒有任何他們已經work.So什麼是與Android N的問題?它應該如此艱難?
這是一個被拋出
FATAL EXCEPTION: main
Process: com.android.gallery3d, PID: 5735
java.lang.SecurityException: Permission Denial: writing android.support.v4.content.FileProvider uri content://my.package.name/external_files/Android/data/my.package.name/cache/0.5062300225583558.png from pid=5735, uid=10071 requires the provider be exported, or grantUriPermission()
at android.os.Parcel.readException(Parcel.java:1683)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:183)
at android.database.DatabaseUtils.readExceptionWithFileNotFoundExceptionFromParcel(DatabaseUtils.java:146)
at android.content.ContentProviderProxy.openAssetFile(ContentProviderNative.java:621)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1000)
at android.content.ContentResolver.openOutputStream(ContentResolver.java:742)
at android.content.ContentResolver.openOutputStream(ContentResolver.java:718)
at com.android.gallery3d.filtershow.crop.CropActivity$BitmapIOTask.<init>(CropActivity.java:408)
at com.android.gallery3d.filtershow.crop.CropActivity.startBitmapIO(CropActivity.java:339)
at com.android.gallery3d.filtershow.crop.CropActivity.startFinishOutput(CropActivity.java:311)
at com.android.gallery3d.filtershow.crop.CropActivity$1.onClick(CropActivity.java:117)
at android.view.View.performClick(View.java:5610)
at android.view.View$PerformClick.run(View.java:22260)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6077)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
09-30 13:19:44.376 11909-11942/volo.global.pingbing E/FA: Task exception on worker thread: java.lang.IncompatibleClassChangeError: The method 'java.io.File android.support.v4.content.ContextCompat.getNoBackupFilesDir(android.content.Context)' was expected to be of type virtual but instead was found to be of type direct (declaration of 'com.google.firebase.iid.zzg' appears in /data/app/volo.global.pingbing-1/base.apk): com.google.android.gms.measurement.internal.zzt.zzEd(Unknown Source)
請發表您的[logcat的(http://www.cmstactical.net/uploads/4/8/9/1/48914725/9763380_orig.jpg)將幫助我們更得到您的問題。 – Gattsu
一分鐘病後 –
這是授予SD讀/寫權限的不正確方法,請參閱[此鏈接](https://developer.android.com/training/permissions/requesting.html) – Gattsu