简体   繁体   中英

CameraRoll.deletePhotos([uri]) @react-native-community/cameraroll com.om has no access to content://media/external/images/media/88****

Description : I wanted to delete an image using deletePhotos() function of cameraroll library (worked perfectly on iOS) problem arrived when I tested the code in android.

The goal of the Project : It's a simple Gallery app which should be able to do simple things like, [view, create, delete, etc.](whatever a gallery does).

Problem Faced : Unable to perform delete action from cameraRoll library.(again, problem is on android only works fine with ios)

Expected Result : Photo should have gotten deleted from the..../DCIM/Camera/xxx.jpg path.

I followed all the installation specifications provided by the library which are:

1st Step:

added above two lines in AndroidManifest.xml file.

2nd Step <manifest... > <application android:requestLegacyExternalStorage="true"... >...

added above requestLegacyExternalStorage in tag in AndroidManifest.xml file.

3rd Step Ask for Permission Pop up

 async function hasAndroidPermission() { const permission = PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE; const hasPermission = await PermissionsAndroid.check(permission); if (hasPermission) { return true; } const status = await PermissionsAndroid.request(permission); return status === 'granted'; } async function savePicture() { if (Platform.OS === "android" &&;(await hasAndroidPermission())) { return; } };

Run the above function for the permission requirement.

Now after all these configurations they(Library creators) ask that: "On Android, the tag must be a local image or video URI, such as "file:///sdcard/img.png"."

(According to my research: Now they ask this because earlier they used to give content://media/external/images/media/88**** uris when we used getPhotos() function of the library. These content uris are restricted uris and we cannot modify these kind if uris...)

But now we get actual local uris like: "file:///storage/emulated/0/DCIM/Camera/20220726_015650.jpg"

So obviously, if I got local uri from getPhotos(), I used this local uri to delete the photo. But here comes the tricky part---> When I ran this function I got the error:

com.om has no access to content://media/external/images/media/88 **** (everything in red:) ).

在此处输入图像描述

Now this error is kind of funny because if I am sending a file:// URI then why the error is coming about content uri.

To find out why it is happening I dived into the library and found out that before deleting the file they are converting the URI to content uri......Dont know why.... But this finding was actually not helpful....So you can ignore this.

Now the error is a permission error but I have when I am calling: const hasPermission = await PermissionsAndroid.check(permission); it is returning true.(Which means that I have the permission), then I don't know where I am lacking.

Conclusion: I want to delete photos but even after all permission granted I am unable to achieve it and instead I am getting the error.

Please Help.. Thanks..

I think you probably found the source of the issue already: To find out why it is happening I dived into the library and found out that before deleting the file they are converting the URI to content uri......

If the issue is that content URIs are not allowed for deletion, try editing the library code so that it doesn't convert the URI first. If that works for you, you can run npx patch-package <library-name> to keep the changes.

Either way, I would raise this issue on their github repo (if an issue for it doesn't already exist), and let them know whether you were able to solve it. It sounds like an easily reproducible problem that the maintainers could investigate.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM