将我的代码更新为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