0

AndroidManifest.xml

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 

应用程序.js

  const App = () => {

  const [uri, setUri] = useState("/storage/emulated/0/DCIM/Screenshots/Screenshot_20200902-162017_Netflix.jpg")

    const requestPermission = async () => {
        await PermissionsAndroid.request(
        PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE,
        {
            title: 'Get Read External Storage Access',
            message: 'get read external storage access for detecting screenshots',
            buttonNeutral: 'Ask Me Later',
            buttonNegative: 'Cancel',
            buttonPositive: 'OK',
        }
        );
    }

    const requestPermission2 = async () => {
        await PermissionsAndroid.request(
        PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
        {
            title: 'Get Read External Storage Access',
            message: 'get read external storage access for detecting screenshots',
            buttonNeutral: 'Ask Me Later',
            buttonNegative: 'Cancel',
            buttonPositive: 'OK',
        }
        );
    }

    useEffect(() => {
        requestPermission()
        requestPermission2()

    },[])  

   return (
        <View style={styles.container}>
        <Image
            source={{uri : `file://${uri}`}}
            style={{height:'100%', width:'100%'}}
        />

        </View>
   );
};

当我进入应用程序设置时,我获得了许可

“/storage/emulated/0/DCIM/Screenshots/Screenshot_20200902-162017_Netflix.jpg 文件是实际存在的。

为什么我什么都看不到

4

0 回答 0