Владислав
Владислав

Reputation: 67

CameraRoll don't show images on android in react-native

I have this code in my react-native project

    CameraRoll.getPhotos({
    first: 20,
    assetType: "Photos",
  }).then((answer) => {
      dispatch({
        type: PHOTOS_LIBRARY,
        photos: answer.edges,
      });
      console.log(answer.edges);
    })
    .catch((err) => {
      console.log(err);
    });

And it work nice on my old android device, but don't work on emulator and more powerful devices, it not show photos, in fact, it return object of photos, but with null dimensions. This console.log:

    [{"fileSize": null, "filename": null, "height": null, "id": 0, "playableDuration": null,
 "uri": "file:///storage/emulated/0/DCIM/Camera/IMG_20200902_153713.jpg", "width": null}, 
{"fileSize": null, "filename": null, "height": null, "id": 1, "playableDuration": null, "uri":
 "file:///storage/emulated/0/DCIM/Camera/IMG_20200902_153653.jpg", "width": null}]

Upvotes: 2

Views: 1164

Answers (2)

Jonatas Campos Martins
Jonatas Campos Martins

Reputation: 106

I had a same problem with galaxy A50 and SDK Version 29.

Fix this add this line in: android/app/src/main/AndroidManifest.xml

<application
...
android:requestLegacyExternalStorage="true"
...
android:theme="@style/AppTheme">

Upvotes: 1

Emerson Oliveira
Emerson Oliveira

Reputation: 26

Have you tried using include in your CameraRoll.getPhotos () method? Ex:

 CameraRoll.getPhotos({
  first: 25,
  assetType: 'Photos',
  include: ['filename', 'imageSize'],
})

Upvotes: 1

Related Questions