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:requestLegacyExternalStorage ="true"

这个办法,能够应用短期修复程序来解决此问题。

我认为这是由于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的更多相关文章

  1. React Native 安卓 程序运行报错: React Native version mismatch(转载)

    这个问题已经得到解决,参照stackoverflow上的问题:https://stackoverflow.com/que...这个问题的原因就处在Android工程中app/build.gradle中 ...

  2. React Native新项目启动报错'React/RCTBridgeDelegate.h' file not found

    React Native版本:0.60.4 解决方法: cd ios pod deintegrate pod install 然后重新启动就好了(示例页面变样了( ⊙ o ⊙ )) END------ ...

  3. npm install模块时 报错:not such file or directory

    通过报错信息可以知道,是因为缺少 package.json 这个文件. 解决方法: 首先,初始化项目,一路回车就行 npm init -f 接着安装依赖 npm install formidable ...

  4. iOS原生项目中集成React Native

    1.本文的前提条件是,电脑上已经安装了CocoaPods,React Native相关环境. 2.使用Xcode新建一个工程.EmbedRNMeituan [图1] 3.使用CocoaPods安装Re ...

  5. react native 之 在现有的iOS工程中集成react native

    在现有的iOS工程中集成react native, 或者说将react native引入到iOS 项目,是RN和iOS混合开发的必经之路 参考官网教程:https://reactnative.cn/d ...

  6. 现有iOS项目集成React Native过程记录

    在<Mac系统下React Native环境搭建>配置了RN的开发环境,然后,本文记录在现有iOS项目集成React Native的过程,官方推荐使用Cocoapods,项目一开始也是使用 ...

  7. linux下, 再次遇到使用thinkphp的模板标签时,报错used undefined function \Think\Template\simplexml_load_string() 是因为没有安装 php-xml包

    linux下, 使用thinkphp的模板标签,如 eq, gt, volist defined, present , empty等 标签时, 报错: used undefined function ...

  8. WPF加载Winform窗体时 报错:子控件不能为顶级窗体

    一.wpf项目中引用WindowsFormsIntegration和System.Windows.Forms 二.Form1.Designer.cs 的 partial class Form1 设置为 ...

  9. iOS原生项目集成React Native模块

    今天周末,弄弄Native和React Native之间的交互.首先,先在iOS原生项目中集成React Native模块: 注意事项: 1.因为react native的版本问题,部分细节可能有所不 ...

随机推荐

  1. KMP算法-从入门到进阶

    题目描述 给定一个文本串text和模式串pattern,从文本串中找出模式串第一次出现的位置 先来看最简单的方法,方便理解题目,也就是暴力求解 暴力求解 放大上面的图,得到下面这个.题目要求匹配到整个 ...

  2. 电力规约DL/T 654 2007多功能电表通信协议 调试工具

    DL/T 654 2007多功能电表通信协议 调试工具 最近调试DL/T654 2007电力规约,在网上找到一个比较好用的工具,分享给大家,希望对大家有帮助. CSDN需要积分,我传百度网盘了, 内含 ...

  3. 入门实践,Python数据分析

    1-2 Anaconda和Jupyter notebook介绍 很多人学习python,不知道从何学起.很多人学习python,掌握了基本语法过后,不知道在哪里寻找案例上手.很多已经做案例的人,却不知 ...

  4. Azure DevOps+Docker+Asp.NET Core 实现CI/CD(二.创建CI持续集成管道)

    前言 本文主要是讲解如何使用Azure DevOps+Docker 来实现持续集成Asp.NET Core项目(当然 也可以是任意项目). 上一篇: Azure DevOps+Docker+Asp.N ...

  5. 【Python学习笔记】字符串拼接方法(5种)总结

    字符串的 5 种拼接方法: “+”号 “,”号 直接连接 格式化 多行字符串拼接 第一种:“+”号 print("Hello"+"Python") 打印结果: ...

  6. Python爬虫获取百度贴吧图片

    #!/usr/bin/python# -*- coding: UTF-8 -*-import urllibimport re文章来源:https://www.cnblogs.com/Axi8/p/57 ...

  7. IndexFlatL2、IndexIVFFlat、IndexIVFPQ三种索引方式示例

    上文针对Faiss安装和一些原理做了简单说明,本文针对标题所列三种索引方式进行编码验证. 首先生成数据集,这里采用100万条数据,每条50维,生成数据做本地化保存,代码如下: import numpy ...

  8. C#图解教程(第四版)—03—类和继承

    1 使用基类的引用 派生类的实例由  基类的实例   加上  派生类 新增的成员 组成. 派生类的  引用   指向整个类对象,包括基类部分 重点:使用对象的  基类部分的引用  来访问对象   (父 ...

  9. java.util.Scanner中hasNext()方法和next()方法的区别

    先说结论: 两者均根据空格划分数据 两者在没有数据输入时均会等待输入 next()方法会将空格划分的数据依次输出,运行一次,输出一个 hasNext()方法会跟着next()方法移动,当前数据不为空, ...

  10. noip复习——快速幂

    \(a ^ n \bmod p\) \(a, p, n \leq 10^9\) 最普通的二进制拆分 #define LL long long LL qpow(LL a, LL n, LL p) { L ...