Плагин файла Cordova (cordova.file.externalDataDirectory) - сохраните и загрузите файл pdf на устройстве Huawei
Мы используем путь cordova.file.externalDataDirectory для записи и загрузки файла для устройств Android. Это отлично работает для всех других устройств Android, кроме устройств Huawei без сервисов Google.
Я добавил плагин cordova-plugin-permission и проверяю, есть ли у приложения разрешение на WRITE_EXTERNAL_STORAGE, прежде чем продолжить загрузку.
Мой код использовался для сохранения и загрузки файла, как показано ниже:
var contentType = "application/pdf";
var fileName = "MyStmt.pdf";
var b64Str = pdfData;
var folderpath = cordova.file.externalDataDirectory;
savebase64AsPDF:function(folderpath, filename, content, contentType) {
var DataBlob = b64toBlob(content, contentType);
window.resolveLocalFileSystemURL(folderpath, function (dir) {
// alert("Access to the directory granted succesfully");
dir.getFile(filename, {
create: true
}, function (file) {
// alert("File created succesfully.");
file.createWriter(function (fileWriter) {
// alert("Writing content to file");
fileWriter.write(DataBlob);
resolveLocalFileSystemURL(fileWriter.localURL, function (entry) {
var nativePath = entry.toURL();
// alert('Native URI: ' + nativePath);
cordova.plugins.fileOpener2.open(nativePath, // You can also use a Cordova-style file uri: cdvfile://localhost/persistent/Download/starwars.pdf
contentType, {
error: function (e) {
//alert('Error status: ' + e.status + ' - Error message: ' + e.message);
}
, success: function () {
// alert('file opened successfully');
}
});
})
}, function () {
// alert('Unable to save file in path '+ folderpath);
});
});
});
}