Ionic Cordova 在 Android 2 上保存 pdf 文件时收到错误代码 13

Ionic Cordova Getting error code 2 when saving pdf file on Android 13

提问人:Emil K 提问时间:10/30/2023 更新时间:10/30/2023 访问量:43

问:

我有一个应用程序,可以将从网络下载的文件保存到手机上。升级到 Android 13 时,它不起作用。之前的所有更改都适用于 android 11 和 12。此外,尽管我知道 Android 13 中的权限更改,但未显示权限请求。只是不确定它是否在后台检查

预计会发生什么?

我希望文件保存在手机上,我可以触发谷歌驱动器打开文件,以便用户可以查看pdf文件。

实际发生了什么?

我收到错误{“code”: 2 },即当我尝试创建文件时SECURITY_ERR。查一下,它与权限问题有关

信息

我当前保存文件的代码 ' 异步 saveImageToDevice(文件夹路径,文件名,内容,内容类型){

const loading = await this.loadingCtrl.create();
await loading.present();

//Determine a native file path to save to
let filePath = '';
if(this.plt.is('android')) {
  filePath = this.file.externalRootDirectory + "/Download";
} else if(this.plt.is('ios')) {
  filePath = this.file.documentsDirectory;
} else {
  this.file.cacheDirectory
}
// let filePath = (this.plt.is('android')) ? this.file.externalRootDirectory : this.file.cacheDirectory;

//Write the file
if (this.plt.is("pwa")) {
  const url = window.URL.createObjectURL(
    content
  );
  const link = window.document.createElement("a");
  link.href = url;
  link.setAttribute("download", filename);
  window.document.body.appendChild(link);
  link.click();
  link.remove();
  await loading.dismiss();
} else {
  return this.file.writeFile(
    filePath,
    filename,
    content,
    { replace: true}
  ).then((success)=> {
    loading.dismiss();
    this.logging.log("File created Succesfully" + JSON.stringify(success))
    this.alertMessage('File downloaded to device. Check downloads for the receipt file.', filename)
  })
  .catch((err) => {
    loading.dismiss();
    this.logging.error("Error creating file: " + JSON.stringify(err));
    this.notification.showAlert("Error","Error creating file: " + JSON.stringify(err));
    throw err;  //Rethrow - will be caught by caller
  });
}

}`

版本信息

离子的:

离子 CLI:6.19.1 (C:\Users....\AppData\Roaming\npm\node_modules@ionic\cli) 离子框架:@ionic/angular 6.7.5 @angular-devkit/build-angular:14.2.13 @angular-devkit/原理图:14.2.13 @angular/cli:14.2.13 @ionic/angular工具包:6.1.0

科尔多瓦:

科尔多瓦命令行界面:11.0.0 科尔多瓦平台:android 12.0.1 Cordova 插件:cordova-plugin-ionic-keyboard 2.2.0、cordova-plugin-ionic-webview 5.0.0(和其他 19 个插件)

效用:

科尔多瓦分辨率:0.15.4 本机运行(可用更新:1.7.2):1.6.0

系统:

Android SDK 工具:26.1.1 (C:\Users...\AppData\Local\Android\Sdk) NodeJS:v16.14.2 (C:\Program Files\nodejs\node.exe) npm:8.5.0 操作系统 : Windows 10

Package.json

{ ... "dependencies": { ... "@awesome-cordova-plugins/file": "^6.4.0", ... }, "devDependencies": { ... "cordova-plugin-file": "^8.0.0", ... }, "description": "An Ionic project", "cordova": { "plugins": { ... "cordova-plugin-file": { "ANDROIDX_WEBKIT_VERSION": "1.4.0" } }, "platforms": [ "android" ] } }

Angular Android-Studio Cordova 离子框架

评论


答: 暂无答案