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

embedded/2024/9/29 11:21:30/

背景:

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/embedded/119321.html

相关文章

AI大模型的基本流程

这篇文章主要是记录自己的问题&#xff0c;虽然说AI大数据模型已经出现了很久&#xff0c;但是一直找不到它与企业的关系&#xff0c;因为有ghat gpt,只要应用这个人工智能就可以了&#xff0c;所以思想一直没有转变过来。 昨天梳理了一下AI大数据的模型&#xff0c;解答了我的…

【go入门】变量

目录 前言变量变量声明指定变量类型&#xff0c;如果没有初始化&#xff0c;默认为零值&#xff0c;零值是变量没有初始化系统默认的值根据值自行判断变量类型: 声明变量多变量声明 注意事项变量的生命周期 前言 本专栏将直接从go语言的内容开始&#xff0c;不会介绍go语言的前…

[论文精读]TorWard: Discovery, Blocking, and Traceback of Malicious Traffic Over Tor

期刊名称&#xff1a;IEEE Transactions on Information Forensics and Security 发布链接&#xff1a;TorWard: Discovery, Blocking, and Traceback of Malicious Traffic Over Tor | IEEE Journals & Magazine | IEEE Xplore 中文译名&#xff1a;TorWard&#xff1a;…

AdaptIoT——制造业中使用因果关系的自我标签系统

0.概述 论文地址&#xff1a;https://arxiv.org/abs/2404.05976 在许多制造应用中&#xff0c;机器学习&#xff08;ML&#xff09;已被证明可以提高生产率。针对制造业应用提出了一些软件和工业物联网&#xff08;IIoT&#xff09;系统&#xff0c;以接收这些 ML 应用。最近&…

yakit使用教程(一,下载并进行基础配置)

一&#xff0c;yakit简介 YAKIT&#xff08;Yet Another Knife for IT Security&#xff09;是一款网络安全单兵工具&#xff0c;专为个人渗透测试员和安全研究人员设计。它整合了一系列实用的安全工具&#xff0c;例如密码破解工具、网络扫描器、漏洞利用工具等&#xff0c;帮…

uni-app+vue3+pina实现全局加载中效果,自定义全局变量和函数可供所有页面使用

首先自定义一个加载中组件 ccloading.vue <template><view class"request-loading-view" v-if"loadingShow"><view class"loading-view"><image class"loading-img" :src"loading" mode"aspectF…

WebView is not allowed in privileged processes

1、现象 最近客户提出一个问题&#xff0c;应用使用webview加载网页时&#xff0c;提示“For security reasons, WebView is not allowed in privileged processes”&#xff0c;然后网页无法加载。2、分析 通过该提示&#xff0c;在源码中找到了报出该提示的所在之处。出于安全…

pytorch ----【输入张量.data.size()/输入张量.size()】的使用

import torch test_data torch.randn(1, 12, 32, 32) batchsize, num_channels, height, width test_data.data.size() 在提供的代码中&#xff0c;test_data 是一个形状为 (1, 12, 32, 32) 的随机张量&#xff0c;表示一个批次&#xff08;batch&#xff09;中有 1 张图像&…