Android permission when using Cameraroll to save photo in gallery using React-Native

Asked

Viewed 85 times

-1

I’m creating a wallpaper app, but the most important part is the download button I can’t make it work, I’m using Touchableopacity and inside create the function

<TouchableOpacity onPress={
    async () => {
        try {
            const granted = PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE

            if (Platform.OS === "android" && granted === PermissionsAndroid.RESULTS.GRANTED) {
                await CameraRoll.saveToCameraRoll(item);
                alert('foto salva')
            } else {
                console.log("Permissao de camera negada.");
                alert('permissão negada')
            }
        } catch (err) {
            console.warn(err);
        }

}

} style={styles.button}>
    <Text style={styles.buttonText}>Download</Text>
</TouchableOpacity>

this item passed as parameter is the object of the photo itself, when I click the download button it falls in the permission log denied, if someone knows how to solve or has some implementation to save photo in the gallery thank you.

1 answer

0

With just this line of code makes it difficult to help, my tip is you use the @React-Native-community/cameraroll, do not use React Native’s Cameraroll, it is deprecated, (you can see it here)

Remember that before implementing the use in your code, you must configure the permission in the files, ... Mainapplication.java, ...Settings.Gradle, ...build.Gradle, ... Androidmanifest.xml, you can see it here.

Let me know if I helped you.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.