Cordova9: - Копирование и воспроизведение файлов содержимого в "TEMP" или "Download" не работает с Android API 29 - PullRequest
0 голосов
/ 07 августа 2020

Ioni c:

Ioni c CLI: 6.11.0 (/ usr / local / lib / node_modules / @ ionic / cli) Ioni c Framework: ionic1 1.3.4 @ionic / v1-toolkit: 1.0.22

Конденсатор:

Конденсатор CLI: 2.4.0 @ конденсатор / сердечник: 2.4.0

Кордова:

Cordova CLI: 9.0.0 (cordova-lib@9.0.1) Платформы Cordova: нет Плагины Cordova: нет плагинов в белом списке (всего 0 плагинов)

Утилита:

cordova-res (доступно обновление: 0.15.1 ): 0.14.0 собственный запуск: 1.0.0

Система:

Android Инструменты SDK: 26.1.1 NodeJS: v10.19.0 (/ usr / bin / node) npm: 6.14.7 ОС: Linux 5.4

JS код файла

$ scope.rewriteDecryptFile = function (encryptedFileUrl, decryptedString, existingFileName, mediaObject) {writeLogsToFile ('debug ',' rewriteDecryptFile -> '+ cordova.file.applicationStorageDirectory, 2); SpinnerAndAlertService.showSpinner (1, «пожалуйста, подождите»); window.requestFileSystem (LocalFileSystem.PERSISTENT, 0, function gotFileSystemSuccess (fileSystem) {writeLogsToFile ('debug', 'Got the FS', 2);

        if (localStorage.getItem("vlearn_devicePlatform") == "0") {
            $scope.relativeFileDirectory = cordova.file.dataDirectory + 'contents/';

            $cordovaFile.checkFile($scope.relativeFileDirectory + "decrypted/", "decrypted_" + existingFileName).then(function gotDecryptedFileSuccess(decryptedFileObject) {
                writeLogsToFile('debug', 'got the decrypted file..trying to play it..', 2);
                // check for file extension PDF
                if ((existingFileName.indexOf('.pdf') > 0) || (existingFileName.indexOf('.PDF') > 0)) {
                    writeLogsToFile('debug', 'already decrypted PDF file found..hence moving it to public path..', 2);
                    SpinnerAndAlertService.closeSpinner();
                    // if PDf move to public path inside /Downloads/vitidocs
                    $cordovaFile.checkDir(TEMP_FILE_PATH+"/Download/", "vitidocs").then(function success(result) {
                        writeLogsToFile("info","Public directory wasnt there..hence created it..",2);
                        if (result.isDirectory == true) {
                            //copy the file from decrypted folder to public path
                            $cordovaFile.copyFile($scope.relativeFileDirectory + "decrypted/", "decrypted_" + existingFileName, TEMP_FILE_PATH+"/Download/myapp/", existingFileName).then(function success(fileCopiedObject) {
                                writeLogsToFile("debug", 'file copied to public path successfully..hence trying to load the media..' + JSON.stringify(fileCopiedObject), 2);
                                $scope.loadMedia(mediaObject, existingFileName, fileCopiedObject.nativeURL);
                            }, function failure() {
                                writeLogsToFile("debug", 'Unable to copy the file to public path', 2);
                            })
                        }
                    }, function failure(error) {
                        //if the content directory doesnt exist then create it
                        if (error.code == 1 && error.message == "NOT_FOUND_ERR") {
                            //create a directory in app storage
                            $cordovaFile.createDir(TEMP_FILE_PATH+"/Download/", "myapp", true).then(function success(result) {
                                writeLogsToFile("debug", "Public Directory created successfully!", 3);

                                //copy the file from decrypted folder to public path
                                $cordovaFile.copyFile($scope.relativeFileDirectory + "decrypted/", "decrypted_" + existingFileName, TEMP_FILE_PATH+"/Download/myapp/", existingFileName).then(function success(fileCopiedObject) {
                                    writeLogsToFile("debug", 'file copied to public path successfully..hence trying to load the media..' + JSON.stringify(fileCopiedObject), 2);
                                    $scope.loadMedia(mediaObject, existingFileName, fileCopiedObject.nativeURL);
                                }, function failure() {
                                    writeLogsToFile("debug", 'Unable to copy the file to public path', 2);
                                })
                            }, function failure(error) {
                                writeLogsToFile("error", "Could not create the public directory.." + JSON.stringify(error), 3);
                            });
                        }
                    });
...