Issue
I am using React Native 0.63. I wanted to display images in a FlatList from my phone's device storage and was using <Image/>
for the renderItem
prop of FlatList.
Using the source
prop, I added a uri
key but I am still not able to see the images. The image tiles are being generated in the FlatList and I am able to see the thin scrollbar on the right when I try to scroll over the list.
This is what I am doing to display the image. (The uri
used here is of an image which I got from the CameraRoll.getPhotos()
API)
<Image
source={{ uri: 'file:///storage/emulated/0/Pictures/Twitter/20201019_160855.jpg'}}
style={{ height: 100, width: 100 }}
/>
I have made sure about the following:
- Allowed
READ_EXTERNAL_STORAGE
andWRITE_EXTERNAL_STORAGE
permissions for the application. - Added
file://
prefix to the file. - Made sure
source={{ uri: ... }}
in<Image/>
works for external links, tried using Google logo, random jpegs from the internet.
Another thing which I noticed is, I am using Samsung phone with Android 10 on my device where I am facing this issue. I tried running this on the Google Nexus 5 Android Emulator which also runs on Android 10 and works perfectly fine (By this, I mean I am able to access the emulator's device storage and not using the exact same uri
specified above).
UPDATE: Tried compiling the application on Android 7, the above thing is working fine. Any issue with the the SDK Versions?
Solution
Are you getting a permission denied error?
This might be helpful: https://github.com/react-native-image-picker/react-native-image-picker/issues/1259
Something to try adding:
android:requestLegacyExternalStorage="true"
... to the tag in your AndroidManifest.xml.
Warning:
From May 5 2021 onwards: Play Store will not accept this implementation and remove all apps using it except if the app functionally really requires it and it needs to be requested.
The implementation will need to use Scoped Storage.
Answered By - sepulturkey
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.