简体   繁体   English

CameraRoll.deletePhotos([uri]) @react-native-community/cameraroll com.om 无权访问 content://media/external/images/media/88****

[英]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.描述:我想使用 cameraroll 库的 deletePhotos() function 删除图像(在 iOS 上完美运行)当我在 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)面临的问题:无法从 cameraRoll 库中执行删除操作。(同样,问题出在 android 仅适用于 ios)

Expected Result : Photo should have gotten deleted from the..../DCIM/Camera/xxx.jpg path.预期结果:照片应该已从..../DCIM/Camera/xxx.jpg 路径中删除。

I followed all the installation specifications provided by the library which are:我遵循了库提供的所有安装规范,它们是:

1st Step:第一步:

added above two lines in AndroidManifest.xml file.在 AndroidManifest.xml 文件中添加以上两行。

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

added above requestLegacyExternalStorage in tag in AndroidManifest.xml file.在 AndroidManifest.xml 文件的标签中添加了上述 requestLegacyExternalStorage。

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.运行上述 function 以获得权限要求。

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"."现在,在完成所有这些配置后,他们(库创建者)要求:“在 Android 上,标签必须是本地图像或视频 URI,例如“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...) (根据我的研究:现在他们问这个是因为早些时候他们曾经在我们使用库的 getPhotos() function 时提供 content://media/external/images/media/88**** uris。这些内容 uris 受到限制uris,如果 uris...,我们不能修改这些类型)

But now we get actual local uris like: "file:///storage/emulated/0/DCIM/Camera/20220726_015650.jpg"但现在我们得到了实际的本地 uri,例如:“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.所以很明显,如果我从 getPhotos() 获得本地 uri,我会使用这个本地 uri 删除照片。 But here comes the tricky part---> When I ran this function I got the error:但棘手的部分来了--->当我运行这个 function 时,我得到了错误:

com.om has no access to content://media/external/images/media/88 **** (everything in red:) ). com.om 无权访问 content://media/external/images/media/88 ****(所有内容均为红色:))。

在此处输入图像描述

Now this error is kind of funny because if I am sending a file:// URI then why the error is coming about content uri.现在这个错误有点好笑,因为如果我发送一个file:// URI,那么为什么会出现关于内容 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.为了找出它发生的原因,我潜入了图书馆,发现在删除文件之前,他们正在将 URI 转换为内容 uri......不知道为什么......但这个发现实际上并没有帮助...... ..所以你可以忽略这个。

Now the error is a permission error but I have when I am calling: const hasPermission = await PermissionsAndroid.check(permission);现在错误是权限错误,但我在调用时遇到了: 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.它返回true。(这意味着我有权限),那么我不知道我缺乏哪里。

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......我想你可能已经找到了问题的根源: 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.如果问题是不允许删除内容 URI,请尝试编辑库代码,使其不会首先转换 URI。 If that works for you, you can run npx patch-package <library-name> to keep the changes.如果这对您有用,您可以运行npx patch-package <library-name>以保留更改。

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.无论哪种方式,我都会在他们的 github repo 上提出这个问题(如果它的问题不存在),并让他们知道你是否能够解决它。 It sounds like an easily reproducible problem that the maintainers could investigate.这听起来像是维护人员可以调查的一个容易重现的问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用React Native在Android上访问Camera和CameraRoll? - Access the Camera and CameraRoll on Android using React Native? Android Studio:错误:模块 [&#39;@react-native-community_cameraroll&#39;, &#39;react-native-community_cameraroll&#39;] 指向同一目录 - Android Studio: ERROR: The modules ['@react-native-community_cameraroll', 'react-native-community_cameraroll'] point to the same directory 拒绝权限:阅读com.android.providers.media.MediaProvider uri content:// media / external / images / media / 38 - Permission Denial: reading com.android.providers.media.MediaProvider uri content://media/external/images/media/38 React Native CameraRoll 权限被拒绝 - React Native CameraRoll permission denied CameraRoll 不在本机反应中在 android 上显示图像 - CameraRoll don't show images on android in react-native React Native-使用CameraRoll Api是否可以访问相机? - React Native - Is this possible to access the camera by using the CameraRoll Api? 图像选择器返回uri`content:// media /`,而无需扩展本机响应 - An image picker returns uri `content://media/` without the extenstion in react native “resolveUri在错误的位图uri上失败:content:// media / external / images / media / 49644”我无法查看图像 - “resolveUri failed on bad bitmap uri: content://media/external/images/media/49644” Im unable to view the image React Native CameraRoll.getPhotos API 似乎没有返回 - React Native CameraRoll.getPhotos API doesn't seem to return RecoverableSecurityException 无法访问 content://media/external/audio/media - RecoverableSecurityException no access to content://media/external/audio/media
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM