集成react-native-image-picker时,报错Couldn't get file path for photo
1. 版本环境:
"react": "16.13.1",
"react-native": "0.63.2",
"react-native-image-picker": "^2.3.3",
targetSdkVersion: 29。
问题还出现在:Android 10/ API 29..
2.出问题时代码:
<TouchableOpacity
style={styles.addBtn}
onPress={() => this.addImages(options)}>
<Text style={styles.addText}>添加照片</Text>
</TouchableOpacity>
addImages = (options) => {
let { imgUrlArray } = this.state;
let length = imgUrlArray.length;
console.log(length)
if(length === 9) {
return;
}
ImagePicker.showImagePicker(options, (response) => {
console.log('Response = ', response);
if (response.didCancel) {
console.log('User cancelled image picker');
} else if (response.error) {
console.log('ImagePicker Error: ', response.error);
} else if (response.customButton) {
console.log('User tapped custom button: ', response.customButton);
} else {
const source = { uri: response.uri, id: length + 1 + '' };
// You can also display the image using data:
// const source = { uri: 'data:image/jpeg;base64,' + response.data };
imgUrlArray.push(source)
this.setState({
imgUrlArray: imgUrlArray,
});
}
});
}
点击后无反应,但是进入了函数。
解决方法:
方案一: android/app/src/main/AndroidManifest.xml 在application标签中加入
这个办法,能够应用短期修复程序来解决此问题。
我认为这是由于Android 10范围内的存储隐私更改所致,并且将需要更新该库以及它如何从文件系统读取/写入。但是我的Android开发经验非常有限。
import { PermissionsAndroid } from “react-native”
//功能函数中加入...
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
{
title: 'We need your permission'
},
);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
console.log('You can use the camera');
ImagePicker.showImagePicker(options, async (response) => {
if (response.didCancel) {
console.log('User cancelled image picker');
} else if (response.error) {
console.log('ImagePicker Error: ', response.error);
console.log(response);
} else if (response.customButton) {
console.log('User tapped custom button: ', response.customButton);
} else {
const source = { uri: response.uri };
}
});
}
else {
console.log('Camera permission denied');
}
集成react-native-image-picker时,报错Couldn't get file path for photo的更多相关文章
- React Native 安卓 程序运行报错: React Native version mismatch(转载)
这个问题已经得到解决,参照stackoverflow上的问题:https://stackoverflow.com/que...这个问题的原因就处在Android工程中app/build.gradle中 ...
- React Native新项目启动报错'React/RCTBridgeDelegate.h' file not found
React Native版本:0.60.4 解决方法: cd ios pod deintegrate pod install 然后重新启动就好了(示例页面变样了( ⊙ o ⊙ )) END------ ...
- npm install模块时 报错:not such file or directory
通过报错信息可以知道,是因为缺少 package.json 这个文件. 解决方法: 首先,初始化项目,一路回车就行 npm init -f 接着安装依赖 npm install formidable ...
- iOS原生项目中集成React Native
1.本文的前提条件是,电脑上已经安装了CocoaPods,React Native相关环境. 2.使用Xcode新建一个工程.EmbedRNMeituan [图1] 3.使用CocoaPods安装Re ...
- react native 之 在现有的iOS工程中集成react native
在现有的iOS工程中集成react native, 或者说将react native引入到iOS 项目,是RN和iOS混合开发的必经之路 参考官网教程:https://reactnative.cn/d ...
- 现有iOS项目集成React Native过程记录
在<Mac系统下React Native环境搭建>配置了RN的开发环境,然后,本文记录在现有iOS项目集成React Native的过程,官方推荐使用Cocoapods,项目一开始也是使用 ...
- linux下, 再次遇到使用thinkphp的模板标签时,报错used undefined function \Think\Template\simplexml_load_string() 是因为没有安装 php-xml包
linux下, 使用thinkphp的模板标签,如 eq, gt, volist defined, present , empty等 标签时, 报错: used undefined function ...
- WPF加载Winform窗体时 报错:子控件不能为顶级窗体
一.wpf项目中引用WindowsFormsIntegration和System.Windows.Forms 二.Form1.Designer.cs 的 partial class Form1 设置为 ...
- iOS原生项目集成React Native模块
今天周末,弄弄Native和React Native之间的交互.首先,先在iOS原生项目中集成React Native模块: 注意事项: 1.因为react native的版本问题,部分细节可能有所不 ...
随机推荐
- Error: Cannot perform an interactive login from a non TTY device
zhangjiawen@zhangjiawen-PC MINGW64 /d/Docker Toolbox$ docker login --username=绝世随机变量 registry.cn-han ...
- 用Python玩连连看是什么效果?
1.前言 Python实现的qq连连看辅助, 仅用于学习, 请在练习模式下使用, 请不要拿去伤害玩家们... 很多人学习python,不知道从何学起.很多人学习python,掌握了基本语法过后,不知道 ...
- Window Server2012 修改远程桌面端口号
Win + R 输入 regedit 打开注册表编辑器 在注册表编辑器中找到 PortNumber 双击 PortNumber,选择10进制,修改想要的端口号 把修改的端口添加为入站规则 重启 Rem ...
- centos 8 安装和网络配置
centos 8 系统安装 系统安装步骤 启动服务器之后选择 Install CentOs Linux 8 选择语言然后下一步 配置 磁盘(Installation Destir) 这里选择默认配置 ...
- SpringCloudAlibaba-服务容错Sentinel(入门)
一:高并发带来的问题? 在微服务架构中,我们将业务拆分成一个个的服务,服务与服务之间可以相互调用,但是由于网络原因或者自身的原因,服务并不能保证服务的100%可用,如果单个服务出现问题,调用这个服务就 ...
- C#LeetCode刷题之#104-二叉树的最大深度(Maximum Depth of Binary Tree)
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/4072 访问. 给定一个二叉树,找出其最大深度. 二叉树的深度为根 ...
- C#设计模式之11-享元模式
享元模式(Flyweight Pattern) 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/409 访问. 享元模式属 ...
- java jsp实现网络考试系统(mysql)
java网络考试系统 功能:可进行学生.管理员登录,学生考试.管理员出卷.列表分页 @ 目录 java网络考试系统 实现效果 主要代码实现 写在最后 实现效果 主要代码实现 package cn.it ...
- STL函数库的应用第二弹——快排sort函数与结构体关键字排序
时隔20多天,本蒟蒻终于记起了他的博客园密码!!! 废话不多说,今天主题:STL快排函数sort()与结构体关键字排序 Part 1:引入和导语 首先,我们需要知道,algorithm库里有一些奇怪的 ...
- iNeuOS工业互联平台,WEB组态(iNeuView)集成rtmp和websocket视频元件,支持海康、大华等摄像头实时显示视频
目 录 1. 概述... 1 2. 平台演示... 2 3. 硬件摄像头... 2 4. 视频流协议转换管理... 2 5. 组态视频元件 ...