import CameraRoll from '@react-native-community/cameraroll'; import RNFS from 'react-native-fs';
Github參考連接:CameraRoll RNFSreact
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
不然會報"Error:Permission denied"錯誤,用來獲取內存空間的讀寫權限。此處須要在頂部引入PermissionsAndroidandroid
requestExternalStoragePermission = async () => { try { const granted = await PermissionsAndroid.request( PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE, { title: 'My App Storage Permission', message: 'My App needs access to your storage ' + 'so you can save your photos', }, ); return granted; } catch (err) { console.error('Failed to request permission ', err); return null; } };