|
|
|
@ -1,9 +1,10 @@
|
|
|
|
|
import {NativeModules, PermissionsAndroid} from 'react-native'
|
|
|
|
|
import {NativeModules, PermissionsAndroid, Platform} from 'react-native'
|
|
|
|
|
import {Dirs, FileSystem} from 'react-native-file-access'
|
|
|
|
|
|
|
|
|
|
export const write = async (name: string, data: string) => {
|
|
|
|
|
const filePath = `${Dirs.DocumentDir}/${name}`
|
|
|
|
|
const permission = async () => {
|
|
|
|
|
if (Platform.OS !== 'android') return true
|
|
|
|
|
const granted = await PermissionsAndroid.request(
|
|
|
|
|
PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE,
|
|
|
|
|
)
|
|
|
|
@ -12,7 +13,7 @@ export const write = async (name: string, data: string) => {
|
|
|
|
|
const granted = await permission()
|
|
|
|
|
if (!granted) return
|
|
|
|
|
await FileSystem.writeFile(filePath, data)
|
|
|
|
|
if (!FileSystem.exists(filePath)) return
|
|
|
|
|
await FileSystem.cpExternal(filePath, name, 'downloads')
|
|
|
|
|
if (Platform.OS === 'android')
|
|
|
|
|
await FileSystem.cpExternal(filePath, name, 'downloads')
|
|
|
|
|
NativeModules.DownloadModule.show(name)
|
|
|
|
|
}
|
|
|
|
|