2

I am trying to create directory in Downloads folder using RNFetcBlob. It doesn't throw any error but folder doesn't get created....

This is the method I am using...

async createAppDir() {
        const granted = await PermissionsAndroid.request(
            PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE
        );

        if (granted === PermissionsAndroid.RESULTS.GRANTED) {
            RNFetchBlob.fs.exists(GlobalVars.APPDIR)
                .then((res) =>
                    {
                        if (!res) {
                            console.log("Creating App directory...", GlobalVars.APPDIR)
                            RNFetchBlob.fs.mkdir(GlobalVars.APPDIR)
                                .then((res) => {console.log("App directory created..")})
                                .catch((err) => {console.log(err)})
                        }
                    }
                );
        }
    }

I have added permissions in AndroidManifest.xml..

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

Console logs....

[Sat Jul 25 2020 10:16:30.966]  LOG      Creating App directory... /storage/emulated/0/Download/gifit/
[Sat Jul 25 2020 10:16:30.967]  LOG      App directory created..
4

2 回答 2

0

尝试这个

async createAppDir() {
    const granted = await PermissionsAndroid.request(
        PermissionsAndroid.PERMISSIONS.WRITE_EXTERNAL_STORAGE
    );

    const isGranted = granted === PermissionsAndroid.RESULTS.GRANTED || granted === true;

    if (isGranted === PermissionsAndroid.RESULTS.GRANTED) {
        const assetsDirExists = await RNFetchBlob.fs.isDir(GlobalVars.APPDIR);
        if(!assetsDirExists) {
            RNFetchBlob.fs.mkdir(GlobalVars.APPDIR)
                            .then((res) => {console.log("App directory created..")})
                            .catch((err) => {console.log(err)})
        }
    }
}
于 2020-07-25T09:05:57.060 回答
0

我在 android/bundle.gradle 文件中更改了以下版本,它开始工作....

更改以下版本

buildToolsVersion = "29.0.2"
minSdkVersion = 16
compileSdkVersion = 29
targetSdkVersion = 29

buildToolsVersion = "28.0.3"
minSdkVersion = 16
compileSdkVersion = 28
targetSdkVersion = 28
于 2020-07-25T11:33:23.897 回答