I want to build a custom gallery using React Native for that I have to read all the images stored on an android device. So I want to know How can I read all image files stored on a device
you need READ PERMISSION from 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');
}
};