简体   繁体   English

我想获取存储在 android 设备中的所有图像,以将它们显示到我的 React Native 应用程序中

[英]I want to get all the images stored in an android device to display them into my React Native app

I want to build a custom gallery using React Native for that I have to read all the images stored on an android device.我想使用 React Native 构建一个自定义图库,因为我必须读取存储在 android 设备上的所有图像。 So I want to know How can I read all image files stored on a device所以我想知道如何读取设备上存储的所有图像文件

you need READ PERMISSION from android您需要 android 的读取权限

import { PermissionsAndroid } from 'react-native';

Try below code after importing above line导入以上行后尝试以下代码

 const requestExternalReadPermission = async () => { try { const granted = await PermissionsAndroid.request( PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE, { title: 'Read Storage Permission', message: 'App needs Read Storage Permission', }, ); // If READ_EXTERNAL_STORAGE Permission is granted return granted === PermissionsAndroid.RESULTS.GRANTED; } catch (err) { console.warn(err); alert('Read permission err', err); } return false; }; const openGallery = async () => { if (Platform.OS === 'android') { if (await requestExternalReadPermission()) { setIsPermitted(true); } else alert('READ_EXTERNAL_STORAGE permission denied'); } };

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 React Native android 应用程序中显示图像? - How to display images in react native android app? 如何在 React Native 应用程序上显示 firebase 存储中的所有图像? - How to display all images from firebase storage on React Native app? 如何在 React Native 中显示 Firebase 存储中的所有图像而不需要图像名称? - How do I display all of the images from my Firebase Storage in React Native without needing image names? 图像未显示在 Android 设备上反应原生 expo - Images are not showing on Android device on react native expo 从反应本机应用程序上传图像后无法将图像保存在我的文件夹中 - Cannot save images in my folder after uploading them from react native app 我需要从本地文件夹中检索所有图像(无论编号和名称如何)并将其显示在我的网站上 - I need to retrieve ALL images (regardless of number and name) from a local folder and display them on my website 本地图像不会显示在我的反应应用程序上 - Local images will not display on my react app 如何在 React 中显示图像,这些图像作为文件下载并保存在服务器上的文件夹中,文件路径存储在我的数据库中? - How do I Display Images in React which are downloaded as Files & saved in a Folder on the Server with the Filepath stored in my Database? 当Android设备未连接到PC时,React Native图像不显示 - React Native images do not show when android device is not connected to PC 为什么我的React Native应用程序无法在我的设备上运行 - Why won't my React Native app run on my device
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM