简体   繁体   中英

Android device directory not creating when i set target api as 29

i have a mobile app in cordova, in that i create directory, if i use Target Api 28, it will create folder, in same time if set Target Api as 29,directory never creating, i am using following code to create directory in internal storage.

 if (device.platform.toLowerCase() == "android") {
            window.resolveLocalFileSystemURL(cordova.file.externalRootDirectory, onFileSystemSuccess, onError);
        } else {
            window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess, onError);
        }
        
        function onFileSystemSuccess(fileSystem) {
        var entry = "";
        if (device.platform.toLowerCase() == "android") {
            entry = fileSystem;
        } else {
            entry = fileSystem.root;
        }
        entry.getDirectory("smfolder", {
            create: true,
            exclusive: false
        }, onGetDirectorySuccess, onGetDirectoryFail);
    };



    function onError(e) {
        alert("Fail to get folder");
    };

This is config.xml screenshot: http://prntscr.com/w53qgh When i upload in Play Store, it will ask to set Target Api level as 29, then only can upload, so i need to set API as 29, is there any thing need to add in config or android manifest file? or need to add permission to use API 29.

Appreciate your assistance since i have been stuck in this for few days now.

Regards,

Aravind

Although I am not a Cordova expert, it seems that the issue is because of Scoped Storage introduced as part of API 29 (Android 10)

It adds some restrictions on how your app can read/write to file system. However, as a work-around, you can opt-out of Scoped Storage to work just like API 28.

Just add android:requestLegacyExternalStorage="true" in manifest file's application tag to opt-out of scoped storage. It should solve your problem.

Make sure your compileSdkVersion is set to 29 to use this attribute.

Please note that if you target API 30 (Android 11), this flag will be ignored by the system and you have to make your app compatible with scoped storage.

More on:https://developer.android.com/about/versions/11/privacy/storage

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM