Mudassir Zakaria
Mudassir Zakaria

Reputation: 437

How can i save screenshot image to phone storage in react native?

This code run successfully but didn't find screenshots in android emulator storage. whats the problem? is there need any change for saving screenshots in phone storage?

return (
      <View style={styles.container}>
        <Text style={styles.welcome}>
          Welcome to React Native SnapShot!
        </Text>
        <Text style={styles.instructions}>
          To get started, edit App.js
        </Text>
        <Text style={styles.instructions}>
          {instructions}
        </Text>
        <Button
          onPress={
            () => {
            captureScreen({
              format: "jpg",
              quality: 0.8
            })
            .then(
              uri => console.log("Image saved to", uri),
              error => console.error("Oops, snapshot failed", error)
            );
          }
          }
          title="capture"
          color="#841584"
          accessibilityLabel="Capture"
        />
      </View>
    );

Upvotes: 1

Views: 2511

Answers (1)

Nisarg Thakkar
Nisarg Thakkar

Reputation: 1547

Please use following module for saving image in local storage https://github.com/francisco-sanchez-molina/react-native-store-photos-album

import CameraRollExtended from 'react-native-store-photos-album'

<Button
  onPress = {
    () => {
      captureScreen({
          format: "jpg",
          quality: 0.8
        })
        .then(
          uri => {
            CameraRollExtended.saveToCameraRoll({
              uri: uri,
              album: 'Name'
            }, 'photo')
          },
          error => console.error("Oops, snapshot failed", error)
        );
    }
  }
/>

Upvotes: 1

Related Questions