jsb.Downloader on android not working

jsb.Downloader on android not working
0.0 0

#1

The following code snippet works fine on iOS but does not work on android. On android it prints only “DOWNLOAD”, but not “SUCCESS”, “PROGRESS”, “ERROR”.

let downloader = null;
const resolveMap = {};
const rejectMap = {};

export function downloadAndSave(url: string, filePath: string): Promise<void> {
    if (!downloader) {
        downloader = new jsb.Downloader();

        downloader.setOnFileTaskSuccess((task) => {
            logNative("SUCCESS");
            resolveMap[task.requestURL]();
        });

        downloader.setOnTaskProgress((task) => {
            logNative("PROGRESS");
        });

        downloader.setOnTaskError((task) => {
            logNative("ERROR");
            rejectMap[task.requestURL]();
        });
    }

    logNative(`DOWNLOAD ${url} ${filePath}`);

    return new Promise((resolve, reject) => {
        resolveMap[url] = resolve;
        rejectMap[url] = reject;

        downloader.createDownloadFileTask(url, filePath, "");
    });
}

Please can you help me to fix it?
I am using Cocos Creator 1.7


#2

Is there another solution for asynchronous file downloading and writing to the local memory, available in Cocos Creator?


#3

Did you try this:

    downloader.setOnFileTaskSuccess((task) => {
        logNative("SUCCESS");
        resolveMap[task.requestURL]();
    });

    downloader.setOnTaskProgress((task, bytesReceived, totalBytesReceived, totalBytesExpected) => {
        logNative("PROGRESS");
    });

    downloader.setOnTaskError((task, errorCode, errorCodeInternal, errorStr) => {
        logNative("ERROR");
        rejectMap[task.requestURL]();
    });

#4

Unfortunately it did not help.
Tested on Huawei Honor DLI-TL20 (Android 7.0) & Samsung SM-J120F (Android 5.1.1).