简体   繁体   中英

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}]

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

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

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">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM