apache / cordova-android

Apache Cordova Android
https://cordova.apache.org/
Apache License 2.0
3.62k stars 1.53k forks source link

Cordova9 :- Content file copy & play in “TEMP” or “Download” not adjusting with Android API 29 #1042

Closed viti3600 closed 3 years ago

viti3600 commented 3 years ago

Ionic:

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

Capacitor:

Capacitor CLI : 2.4.0 @capacitor/core : 2.4.0

Cordova:

Cordova CLI : 9.0.0 (cordova-lib@9.0.1) Cordova Platforms : none Cordova Plugins : no whitelisted plugins (0 plugins total)

Utility:

cordova-res (update available: 0.15.1) : 0.14.0 native-run : 1.0.0

System: Android SDK Tools : 26.1.1 NodeJS : v10.19.0 (/usr/bin/node) npm : 6.14.7 OS : Linux 5.4

if (localStorage.getItem("vdoc_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);
                        });
                    }
                });

============================================ logs

2020-08-09 22:24:06.908 1645-1645/io.ionic.starter I/chromium: [INFO:CONSOLE(35)] "mediaFileName: 5A4D0957.pdf", source: http://localhost/js/logs/writeFileLogs.js (35) 2020-08-09 22:24:06.908 1645-1645/io.ionic.starter I/chromium: [INFO:CONSOLE(37)] "trying to check for file", source: http://localhost/js/logs/writeFileLogs.js (37) 2020-08-09 22:24:06.918 1645-1645/io.ionic.starter I/chromium: [INFO:CONSOLE(37)] "Have the permission to write to storage", source: http://localhost/js/logs/writeFileLogs.js (37) 2020-08-09 22:24:06.919 1645-1645/io.ionic.starter I/chromium: [INFO:CONSOLE(37)] "relativeFileDirectory: file:///data/user/0/io.ionic.starter/files/contents/", source: http://localhost/js/logs/writeFileLogs.js (37) 2020-08-09 22:24:06.930 1645-1645/io.ionic.starter I/chromium: [INFO:CONSOLE(37)] "got the downloaded encrypted file!{"isFile":true,"isDirectory":false,"name":"5A4D0957.pdf","fullPath":"/contents/encrypted/5A4D0957.pdf","filesystem":"","nativeURL":"file:///data/user/0/io.ionic.starter/files/contents/encrypted/5A4D0957.pdf"}", source: http://localhost/js/logs/writeFileLogs.js (37) 2020-08-09 22:24:06.931 1645-1645/io.ionic.starter I/chromium: [INFO:CONSOLE(35)] "Encrypted file already present", source: http://localhost/js/logs/writeFileLogs.js (35) 2020-08-09 22:24:06.931 1645-1645/io.ionic.starter I/chromium: [INFO:CONSOLE(35)] "checking the size of the encrypted file!", source: http://localhost/js/logs/writeFileLogs.js (35) 2020-08-09 22:24:06.947 1645-1645/io.ionic.starter I/chromium: [INFO:CONSOLE(37)] "downloaded file size is: 960679", source: http://localhost/js/logs/writeFileLogs.js (37) 2020-08-09 22:24:06.947 1645-1645/io.ionic.starter I/chromium: [INFO:CONSOLE(37)] "original file size and downloaded file size are equal..", source: http://localhost/js/logs/writeFileLogs.js (37) 2020-08-09 22:24:06.948 1645-1645/io.ionic.starter I/chromium: [INFO:CONSOLE(35)] "decryptFile-->", source: http://localhost/js/logs/writeFileLogs.js (35) 2020-08-09 22:24:06.948 1645-1645/io.ionic.starter I/chromium: [INFO:CONSOLE(35)] "performHeaderDecryption-->", source: http://localhost/js/logs/writeFileLogs.js (35) 2020-08-09 22:24:06.957 1645-1645/io.ionic.starter I/chromium: [INFO:CONSOLE(37)] "Decrypted string before parse: "%PDF-1.4"", source: http://localhost/js/logs/writeFileLogs.js (37) 2020-08-09 22:24:06.957 1645-1645/io.ionic.starter I/chromium: [INFO:CONSOLE(37)] "Decrypted string after JSON parse: %PDF-1.4", source: http://localhost/js/logs/writeFileLogs.js (37) 2020-08-09 22:24:07.015 1645-1645/io.ionic.starter I/chromium: [INFO:CONSOLE(37)] "rewriteDecryptFile-->file:///data/user/0/io.ionic.starter/", source: http://localhost/js/logs/writeFileLogs.js (37) 2020-08-09 22:24:07.053 1645-1645/io.ionic.starter I/chromium: [INFO:CONSOLE(37)] "Got the FS", source: http://localhost/js/logs/writeFileLogs.js (37) 2020-08-09 22:24:07.074 1645-1645/io.ionic.starter I/chromium: [INFO:CONSOLE(37)] "decrypted file not present hence trying to decrypt..", source: http://localhost/js/logs/writeFileLogs.js (37) 2020-08-09 22:24:07.090 1645-1645/io.ionic.starter I/chromium: [INFO:CONSOLE(37)] "Encrypted file not found, hence unable to decrypt it!", source: http://localhost/js/logs/writeFileLogs.js (37)

viti3600 commented 3 years ago

This part of code is not coming up after going with API-29 & Android 9. //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);

Up to API 16 and Android SDK 26 , the folders are created and PDF (contents) is opening

viti3600 commented 3 years ago

Closed