React-Native 中使用 react-native-image-crop-picker 在华为手机上不能正常使用拍照功能

ops/2024/9/24 6:15:18/

背景:

React-Native 0.66 中使用 react-native-image-crop-picker 在安卓 华为手机上不能正常使用拍照功能, 其他品牌正常

代码如下: 

import ImagePicker from 'react-native-image-crop-picker';ImagePicker.openCamera(photoOptions).then(image => {callback(image);})

原因分析及解决办法:

通过在 openCamera中增加 catch 捕获异常发现, 在华为手机上调用拍照时有报错, 

 1. Error: Cannot launch camera

poromiseMethodwrapper@http://localhost :8081/index .bundle?xxx

==>  在 android/app/src/main/AndroidManifest.xml  中增加  android:requestLegacyExternalStorage="true" 配置

2. 再继续调试发现另外报错 

Failed to find configured root that contains /storage/emulated/0/Android/data/com.jgpdapro/files/Pictures/image-4488cf2d-8a66-4254-a9d6-f198bb1515781214910780677416114.jpg

promiseMethodWrapper@http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.jgpdapro&modulesOnly=false&runModule=true:2084:45

http://localhost:8081/index.bundle?platform=android&dev=true&minify=false&app=com.jgpdapro&modulesOnly=false&runModule=true:171700:57

==> 在 android/app/src/main/AndroidManifest.xml  中增加 android.support.FILE_PROVIDER_PATHS 配置

<manifest xmlns:android="http://schemas.android.com/apk/res/android"package="com.xxx"><applicationandroid:name=".MainApplication"android:label="@string/app_name"android:usesCleartextTraffic="true"android:icon="@mipmap/ic_launcher"android:roundIcon="@mipmap/ic_launcher_round"android:allowBackup="false"android:requestLegacyExternalStorage="true" android:theme="@style/AppTheme"><providerandroid:name="androidx.core.content.FileProvider"android:authorities="${applicationId}.provider"android:exported="false"android:grantUriPermissions="true"><meta-dataandroid:name="android.support.FILE_PROVIDER_PATHS"android:resource="@xml/file_paths" /></provider></application>
</manifest>

在 android/app/src/main/res/xml/下新增 file_paths.xml

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android"><external-pathname="external_pictures"path="Android/data/com.xxx/files/Pictures/" />
</paths>

测试结果:


http://www.ppmy.cn/ops/115149.html

相关文章

快递即时查询API接口DEMO下载

物流查询API提供实时查询物流轨迹的服务&#xff0c;用户提供运单号和快递公司&#xff0c;即可查询当前时刻的最新物流轨迹。 应用场景 &#xff08;1&#xff09;电商网站用户打开“我的订单”时调用此API显示物流信息详情。 &#xff08;2&#xff09;电商管理后台的物…

c++234继承

#include<iostream> using namespace std;//public 修饰的成员便俩个和方法都能使用 //protected&#xff1a;类的内部 在继承的子类中可使用 class Parents { public:int a;//名字 protected:int b;//密码 private:int c;//情人public:void printT(){cout << &quo…

黑盒测试 | 挖掘.NET程序中的反序列化漏洞

通过不安全反序列化漏洞远程执行代码 img 今天&#xff0c;我将回顾 OWASP 的十大漏洞之一&#xff1a;不安全反序列化&#xff0c;重点是 .NET 应用程序上反序列化漏洞的利用。 &#x1f4dd;$ _序列化_与_反序列化 序列化是将数据对象转换为字节流的过程&#xff0c;字节流…

vue3知识汇总

vue3.x 0. changelog https://juejin.cn/post/7030992475271495711#heading-0 1. vite//要构建一个 Vite Vue 项目&#xff0c;运行&#xff0c;使用 NPM:npm init vitejs/app 项目名//使用 Yarn:yarn create vitejs/app 项目名//你会觉得非常快速的创建了项目&#xff0c;然…

淘系电商平台店铺所有商品宝贝数据API接口,用json格式示例

以下是一个淘宝店铺所有商品接口数据的 JSON 格式示例&#xff1a; { "status": "success", "message": "商品数据获取成功", "data": { "shop_name": "时尚潮流店铺", "products": [ { &q…

C++ | Leetcode C++题解之第432题全O(1)的数据结构

题目&#xff1a; 题解&#xff1a; class AllOne {list<pair<unordered_set<string>, int>> lst;unordered_map<string, list<pair<unordered_set<string>, int>>::iterator> nodes;public:AllOne() {}void inc(string key) {if (…

【c++】动态内存管理

&#x1f31f;&#x1f31f;作者主页&#xff1a;ephemerals__ &#x1f31f;&#x1f31f;所属专栏&#xff1a;C 目录 前言 一、内存区域分布 二、c中的动态内存管理方式 1. new与delete对内置类型的操作 2. new与delete对自定义类型的操作 三、operator new函数和op…

基于51单片机的矿井安全检测系统

基于51单片机的矿井安全检测系统使用51单片机作为系统主控&#xff0c;LCD1602进行显示同时系统集成了ADC0808和烟雾传感器、甲烷传感器&#xff0c;二者结合测量环境烟雾值&#xff0c;同时使用DHT11温湿度传感器获取环境温湿度值&#xff0c;使用L298N驱动风扇&#xff0c;利…