Display an image stored on phone

后端 未结 3 1397
故里飘歌
故里飘歌 2021-01-02 12:46

I have succesfully been able to take a photo inside my app and store it on the phone, but how do I display it?

I tried this static approach but it does not work (Yes

3条回答
  •  耶瑟儿~
    2021-01-02 13:13


    We should get 'READ_EXTERNAL_STORAGE' Permission


    • Import

    // import 
    import { PermissionsAndroid } from "react-native";
    
    • Function to request permission

    // function to request permission
    requestStoragePermission = async () => {
        try {
          const granted = await PermissionsAndroid.request(
            PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE,
            {
              title: "Permission title",
              message:
                "Permission message",
              buttonNeutral: "Ask Me Later",
              buttonNegative: "Cancel",
              buttonPositive: "OK",
            }
          );
          if (granted === PermissionsAndroid.RESULTS.GRANTED) {
            console.log("You can use the EXTERNAL_STORAGE");
          } else {
            console.log("EXTERNAL_STORAGE permission denied");
          }
        } catch (err) {
          console.warn(err);
        }
      };
    
    • Call the above Function


    Click this for reactnative android permissions docs

提交回复
热议问题