I am working in cross platform using phonegap. When i tried Download Phonegap API in IOS, file is getting downloaded in phone rather in SD Card So its not safe to save it phone,so Please Suggest me solution So that it support both Android and ios to open file to view without downloading.....
Thanks in Advance
For Android:
You can use FileOpener plugin to do the same. This plugin will help you to open all the files store in your asset folder in android and resource folder in iOS. As well as you can open global image as well.
Have a look on this github page you will able to find the plugin.
You no need to download any content.
And For iOS you can use only:
function openFile(url) {
window.open(url, '_blank');
}
You can get file link from server and open in InAppBrowser
var ref = window.open(your_url, 'random_string', 'location=no');
ref.addEventListener('loadstart', function(event) {
});
ref.addEventListener('loadstop', function(event) {
console.log(event.type + ' - ' + event.url);
});
ref.addEventListener('exit', function(event) {
});
Related
I manage to display PDF with phonegap inappbrowser in ios and Android 6 but not Android 8.
Here is the code :
if (platform !== 'Android') {
var ref = window.open(
decodeURI(pdf.filepath),
'_blank',
`location=no,closebuttoncaption=Close,enableViewportScale=yes`
)
} else {
var ref = window.open(
decodeURI(pdf.filepath),
'_system',
`location=no,closebuttoncaption=Close,enableViewportScale=yes`
)
}
The button that trigger this code open a new window, but she’s remains empty. I tried with a wrong path, it shows an error so it’s not a path problem.
Any Idea ?
Finaly I managed to display PDF on Android > 6. It’s not possible to display PDF through inappbrowser for Android > 6 (2 fulltime days of testing and googling...).
I used cordova-plugin-file-opener2. But what’s important to know (I didn’t until yesterday), you can’t test plugins via "phonegap serve" + phonegap app on device !! You need to build the apk, install it and then test it. This important point make me loose my nerves on various plugins...
That’s all.
I have a very critical problem.
I'm developing mobile app on android and iOS using apahce cordova with visual studio 2015.
My app downloads and opens a pdf file from external direct url using file transfer and file opener plugins.
I've successfully downloaded and opened that file on android on device memory.
but no matter how many time i try to do the same thing on iOS , it never works.
I have tried all directories on that link : https://github.com/apache/cordova-plugin-file#where-to-store-files
All i want is a working example of downloading a file in any directory from external server and open it in iOS using apache cordova.
thank you in advance.
I recently had the same problem to solve, and used the file opener 2 plugin, which you use like this:
cordova.plugins.fileOpener2.open(
'path/to/file.pdf',
'application/pdf',
{
error: function(e) {
console.log('Error opening file:' + e);
console.log('path: ' + filePathAndroid);
},
success: function() {
console.log('File opened successfully');
console.log('path: ' + filePathAndroid);
}
}
);
This opens the PDF using an action sheet that shows all the possibilities that the device has for handling it (Adobe Reader if installed, iBooks, AirPrint, send to email etc).
You can use the Cordova file plugin to download the PDF from your server and work out a path to it on the local device.
My sample app that shows a range of ways of handling PDFs for Android and iOS can be found here. There I tried the In App Browser (not great, doesn't work on Android), PDF.js (renders PDF inline in a canvas, but pretty slow and no pinch zoom) and the file opener 2 plugin (most "natural" way to use the device's abilities in my opinion).
Raymond Camden also recently blogged on this subject, you may find his post useful background reading too.
I need to open a pdf in a hybrid app, the pdf is previously downloaded by the hybrid app (the app has both read and write from external storage). I can retrieve via fileSystem the file entry:
someDirEntry.getFile(fileName, {create: true, exclusive: false}, openViewPdf, ioFail);
in openViewPdf I can read the path of the file:
function openViewPdf(fe){
console.log("V1 "+fe.toURL());
console.log("V2 "+fe.fullPath);
//console.error("V3 "+toNativeURL()); //not supported by 2.3.0
window.open(fe.toURL(), '_system');
}
the output is something like:
V1 file:///mnt/sdcard/someDir/fileName.pdf
V2 file:///mnt/sdcard/someDir/fileName.pdf
i.e. there is no difference between fullpath and .toURL(). A new window opens, but in the new window I see an error alert:
There was a network error. (file:///android_asset/www/fileName.pdf
It's like the InAppBrowser tries to open the pdf in the asset directory of the app (which of course is wrong!) the proper path is the ones listed above. Isn't there any way of making this work other than trying the extra plugin (see: Phonegap how to download and open pdf file in android app)?
After plenty of work the answer is: "No, there is no way of opening a pdf with InAppBrowser in Android". The upside is that the plugin is easy to do in java.
I am having issue with InAppBrowser on Android,it is not loading/displaying pdf file.
var ref = window.open('http://178.239.16.28/fzs/sites/default/files/dokumenti-vijesti/sample.pdf', '_blank', 'location=yes');
I tried with _system,it is downloading the file.But I want it as just display without download. I found the same questions in Stackoverflow but didnt find the exact answer as per my requirement.Any help would be appreciated.
Try This..
var ref = window.open("https://docs.google.com/gview?embedded=true&url=http://178.239.16.28/fzs/sites/default/files/dokumenti-vijesti/sample.pdf", '_blank', 'location=yes');
Becuse Andoid Webkit has not power to Directly open pdf as IOS.. So open with google Doc.
Have anyone used Childbrowsers or InAppBrowser plugin for pdf/anydoc viewer in android...IF so how does it work..I need to develop a document viewer for my phonegap Application...Plz suggest something..Thanks :)
Please look at the provided documentation or tells us what you have tried
InAppBrowser is a built in plug-in for the standard phonegap release since version 2.3.0.
Childbrowser was used for version previous to that as a non default plug-in.
Documentation is on the phonegap website
http://docs.phonegap.com/en/2.5.0/cordova_inappbrowser_inappbrowser.md.html#InAppBrowser
Andrdoid does not come with a default PDF viewer. So you may need to open your docs using google document reader and display in your InAppBrowser.
For everybody who is stuck with this problem here is what i´ve finally found out:
HTML 5 object tag: not working
Embedded tag: not working
childBrowser Plugin: I think it would work, but it is designed for the 2.0.0 version. So you´ll get a lot of errors so i didn´t get it to work.
Phonegap InAppViewer: If you use it like that:
window.open('http://www.example.com/test.pdf', '_blank', 'location=yes')
it wont work. The InAppViewer can´t open PDF, it doesn´t matter if the PDF is external or local stored.
My solutions so far (not what the actual idea was):
you can call the window function with _system. like that:
window.open('http://www.example.com/test.pdf', '_system', 'location=yes')
this will open the PDF in the normal Browser and download it. After downloading it will ask if it should open it with a PDF viewer. But you have to go back to your app and open it again after that.
Another possibility would be that you just download it to your sdcard with the Phonegap Filesystem API like that:
var fileTransfer = new FileTransfer();
fileTransfer.download(
"http://developer.android.com/assets/images/home/ics-android.png",
"file://sdcard/ics-android.png",
function(entry) {
alert("download complete: " + entry.fullPath);
},
function(error) {
alert("download error source " + error.source);
alert("download error target " + error.target);
alert("upload error code" + error.code);
});
The last thing i´ve found out is, to use Google docs/drive to open it with the InAppViewer linked to google docs like that:
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
window.open('https://docs.google.com/viewer?url=http://www.example.com/test.pdf&embedded=true', '_blank', 'location=yes');
ref = window.open('index.html', '_self');
}
This will open the PDF in the app viewing it on google docs. You can generate your permalink here: https://docs.google.com/viewer So even if you change your pdf file, it will still work
I hope this summary will help you save time. If there is another solution let me know