集成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的版本问题,部分细节可能有所不 ...
随机推荐
- OS实现流程草稿
实现一个OS需要现在网上搜索 不要在Windows环境下写 nasm等汇编编译器的语法 bois中断函数使用 内存分布 描述符 实模式与保护模式 从实模式到保护模式比较难,可以从网上找一些代码能运行自 ...
- python爬虫:XPath语法和使用示例
python爬虫:XPath语法和使用示例 XPath(XML Path Language)是一门在XML文档中查找信息的语言,可以用来在XML文档中对元素和属性进行遍历. 选取节点 XPath使用路 ...
- week4:周测错题
4.如何在类外,给对象动态添加绑定方法 import types def qingtianzhu(obj,name): print("请我叫我一柱擎天,简称{},颜色是{}".fo ...
- MongoDB学习2:MongoDB的基本操作
以下都是基于MongoShell进行操作 1.使用insert进行插入操作 示例: db.<集合>.insertOne(<JSON对象>) db.<集合>.ins ...
- 走正确的路 - IT业没有护城河 - 机器翻译新锐Deepl
最近发生了一件很令我震惊的事情:新的一个机器翻译网站出现了 - www.deepl.com (DeepL 或许会成为你今年首选的翻译工具) 机器翻译早就是红海市场了.我就不从1954年IBM发布俄翻英 ...
- VM 添加硬盘,分区,挂载
添加硬盘后使用>df -h 命令 VM安装linux系统之后,发现我们的硬盘不够,可通过两种方式添加硬盘 方式一:选择虚拟机,点击右键,设置,点击硬盘,点击添加,输入新添加的硬盘大小,保存与虚拟 ...
- JavaScript学习系列博客_18_JavaScript中的匿名函数
匿名函数 - 用函数声明的方式创建一个函数时,不加函数名称. function sum(){ console.log("我是函数sum")} - 不加名称,这样写浏览器是会报错的. ...
- java程序CPU 100%调试
前置 PID为进程id,NID为线程ID 步骤一.找到最耗CPU的进程 top 然后键入P,按CPU占用率排序(M是按内存排序) 步骤二.找到进程中最耗CPU的线程 top -Hp PID 步骤三.将 ...
- centos yum 安装golang
rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm yum install golan ...
- python中eval, exec, execfile,和compile
eval(str [,globals [,locals ]])函数将字符串str当成有效Python表达式来求值,并返回计算结果. 同样地, exec语句将字符串str当成有效Python代码来执行. ...