问题
I have downloaded an pdf file from the server using Transfer Plugin and i am trying to open the file using InAppBrower plugin i am not getting anything. i mean nothing is happening.
fileTransfer.download(url, this.file.dataDirectory + file.filename,false,{
headers: {
'authorization': 'bearer xxxx'
}
}).then((entry) => {
console.log('download complete: ' + entry.toURL());
console.log(entry.nativeURL);
const browser = this.iab.create(entry.nativeURL, '_system', 'location=yes'); //here the inappbrowser plugin code.
}, (error) => {
// handle error
console.log(error);
console.log('ERROR');
});
my console.log(entry.nativeURL); prints this path
file:///data/user/0/com.schneider.and/files/Attendance_Policy_Ver_1.0.pdf
回答1:
Try putting the nativeUrl in the browserURL and see if you could jump to the exact .pdf....
Then try
fileTransfer.download(url, this.file.dataDirectory + file.filename,false,{
headers: {
'authorization': 'bearer xxxx'
}
}).then((entry) => {
console.log('download complete: ' + entry.toURL());
console.log(entry.nativeURL);
let browser=new InApp Browser(entry.nativeURL,'_blank');
}, (error) => {
// handle error
console.log(error);
console.log('ERROR');
});
And import InAppBrowser from 'ionic-native'
import {InAppBrowser} from 'ionic-native';
回答2:
i use this code and its works for me
showDocument(){
const options: DocumentViewerOptions = {
title: 'My PDF'
}
const imgeLocation = `${cordova.file.applicationDirectory}www/assets/imgs/${'Jainbhajan-Jeevan-Saar-By-Nirmal-Gangwal-1-ilovepdf-compressed (1).pdf'}`;
this.document.viewDocument(imgeLocation, 'application/pdf', options)
}
来源:https://stackoverflow.com/questions/44427319/how-to-open-an-local-pdf-using-inappbrowser