Android 10@离子原生/文件传输/文件打开程序不工作



@ionic native/file transfer/file opener not working I'm get"open failed:EACCES(拒绝权限(error which try to download a pdf and open in my ionic angular project.This is the header files and function to open the attachment.This are working fine in android version 9 but not in 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();
}
}

我已经在AndroidManifest文件中将AndroidTargetSDK版本更改为28。现在它开始工作了。我正在从AndroidStudio运行应用程序。因此,将值更改为28会使其工作。希望这能奏效。

相关内容

最新更新