【问题标题】:Android 10 @ionic-native/file-transfer /file-opener not workingAndroid 10 @ionic-native/file-transfer /file-opener 不工作
【发布时间】:2020-05-05 08:42:24
【问题描述】:

@ionic-native/file-transfer /file-opener not working 我在尝试下载 pdf 并在我的 ionic-angular 项目中打开时收到“打开失败:EACCES(权限被拒绝)错误。这是标题文件和函数来打开附件。这在 android 版本 9 中可以正常工作,但在 android 10 中无法正常工作。这个问题的原因是什么?

头文件

import { FileTransfer, FileTransferObject } from '@ionic-native/file-transfer';
import { File } from '@ionic-native/file';
import { FileOpener } from '@ionic-native/file-opener';
import { PhotoViewer } from '@ionic-native/photo-viewer';

函数调用

constructor(public navCtrl: NavController, public navParams: NavParams,
...
private fileTransfer: FileTransfer,
private platform: Platform,
private file: File,
private fileOpener: FileOpener,
private photo: PhotoViewer,
...
) {...}

openAttachment(attachment) {
this.notification.getNotificationCount(this.userID).subscribe(res => this.setNotificationsCountAtStart(res));
this.loader.displayLoader();
const transfer: FileTransferObject = this.fileTransfer.create();
var filename = attachment.substring(attachment.lastIndexOf('/') + 1);
var filePath;
if (this.platform.is('ios')) {
  filePath = this.file.documentsDirectory + filename;
} else if (this.platform.is('android')) {
  filePath = this.file.externalRootDirectory + 'Download/' + filename;
}
if (attachment.indexOf('.pdf') > -1) {
  transfer.download(this.baseurl + attachment, filePath, true).then((entry) => {
    let url = entry.toURL();
    this.fileOpener.open(url, 'application/pdf')
      .then(() => {
        console.log('File is opened');
        this.loader.hideLoader();
      })
      .catch(e => console.log('Error opening file', JSON.stringify(e)))
  }, (error) => {
    // handle error
    let toast = this.toast.create({
      message: JSON.stringify(error),
      duration: 3000,
      position: 'bottom'
    });
    toast.present();
  });
} else if (attachment.indexOf('.png') > -1) {
  transfer.download(this.baseurl + attachment, filePath, true).then(entry => {
    let url = entry.toURL();
    this.loader.hideLoader();
    this.photo.show(url, filename, {});
  })
} else if (attachment.indexOf('.jpg') > -1) {
  transfer.download(this.baseurl + attachment, filePath, true).then(entry => {
    let url = entry.toURL();
    this.loader.hideLoader();
    this.photo.show(url, filename, {});
  })
} else if (attachment.indexOf('.jpeg') > -1) {
  transfer.download(this.baseurl + attachment, filePath, true).then(entry => {
    let url = entry.toURL();
    this.loader.hideLoader();
    this.photo.show(url, filename, {});
  })
} else {
  this.loader.hideLoader();
}
}

【问题讨论】:

    标签: android angular ionic-framework ionic4


    【解决方案1】:

    我已在 AndroidManifest 文件中将 AndroidTargetSDK 版本更改为 28。现在它的工作。我正在从 AndroidStudio 运行该应用程序。因此,将值更改为 28 使其工作。希望这行得通。

    【讨论】:

      猜你喜欢
      • 2021-01-10
      • 1970-01-01
      • 2021-08-20
      • 1970-01-01
      • 1970-01-01
      • 2020-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多