简体   繁体   中英

How to access photos taken within a camera app in react native expo?

I made a camera app with expo camera module, I now I'm trying to have access into a specific album within this app, like it occurs with mobile native camera applications. I tried to create a function like that one, following some vague instructions I saw, but I have no idea this is the right path.

//trying to access photos taken through the square

const albumName = "Gryffindor";
async function seePhotos() {
  const getTakenPhotos = await MediaLibrary.getAssetsAsync({
    first: 20,
    album: albumName,
    sortBy: ["creationTime"],
  });
  console.log(getTakenPhotos.assets);
  return MediaLibrary.getAssetsAsync.asset.uri;
}

<View style={{ flex: 1, alignItems: "center" }}>
  <Icon name="square" size={50} color="white" onPress={seePhotos} />
</View>;

Replace above code with this

const albumName = "Gryffindor";

const seePhotos = async () => {
  try {
    const getTakenPhotos = await MediaLibrary.getAssetsAsync({
      first: 20,
      album: albumName,
      sortBy: MediaLibrary.SortBy.creationTime, // Should be written like this
    });
    console.log(getTakenPhotos.assets); // Check Your console
  } catch (error) {
    console.log(error); // In case of any error
  }
};

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