Android致命异常:java.lang.UnsupportedOperationException:不支持删除

时间:2019-08-29 04:48:24

标签: android

将我的代码更新为SDK 29后出现异常。

java.lang.UnsupportedOperationException: Delete not supported
        at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:167)
        at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
        at android.content.ContentProviderProxy.delete(ContentProviderNative.java:547)
        at android.content.ContentResolver.delete(ContentResolver.java:1691)
        at com.ashomok.cropimagelib.ScanFragment.getBitmap(ScanFragment.java:84)

当我打电话

getActivity().getContentResolver().delete(uri, null, null);

另一个代码更新

@Override
public void startGalleryChooser() {
    if (Build.VERSION.SDK_INT < 19) {
        Intent intent = new Intent();
        intent.setAction(Intent.ACTION_GET_CONTENT);
        intent.setType("image/*");
        startActivityForResult(Intent.createChooser(intent, getString(R.string.select_photo)),
                GALLERY_IMAGE_REQUEST);
    } else {
        Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
        intent.addCategory(Intent.CATEGORY_OPENABLE);
        intent.setType("image/*");
        startActivityForResult(Intent.createChooser(intent, getString(R.string.select_photo)),
                GALLERY_IMAGE_REQUEST);
    }
}

如何通过向后代码兼容性来处理此异常?

我已获得许可:

Manifest.permission.MANAGE_DOCUMENTS

0 个答案:

没有答案