Document Viewer for phonegap Applications - android

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

Related

inAppBrowser ANDROID reading PDF problems

Coming here, desperately, I really need help with an answer for my question... I do have a inAppBrowser and my can't ready a PDF (after accessing pdf view). I use cordova, phonegap. I know that I can't read a PDF because for android IAB didn't implemented a viewer, but, how can i use plugin FileTransfer? or open(url, _system). From the start, I call my app as open(url, _blank). If I'm pressing on PDF link, want my IAB to be transformed in _system, but when I go back, want my app still be _blank. Or, if I'm accessing a PDF link, to be downloaded, using FileTransfer. I had tried this 2 codes:
FileTransfer:
var fileTransfer = new FileTransfer();
fileTransfer.download(url, "");
If I'm accessing PDF link, nothing happens...
And _system:
cordova.InAppBrowser.open(url, '_system', 'location=no');
This code works fine, but! After I'm accessing PDF link, IAB -> transforms into _system, but when I go back and I press on PDF link again, nothing happens anymore... (so what I want is my IAB, to be _blank again)
Thank you !

Download pdf file to iOS using apache cordova

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.

open PDF with cordova 2.3.0 InAppBrowser

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.

How to Open file without download using phonegap

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) {
});

phonegap jquerymobile : how to open external links via Android Browser

I am working on a project with PhoneGap and JqueryMobile in Android.
Now I need to open an external link via the Android Browser.
I just write
window.location.href("http://stackoverflow.com")
or
window.open("http://stackoverflow.com")
The App didn't reply at all?
Please tell me why and help me out. Thanks.
You need to use navigator.app.loadUrl('http://stackoverflow.com');
EDIT
Some code for PhoneGap always needs to be device-specific. What I do rather than device check is load a "platform" JS file which has code for each feature that has platform-specific code.
So you can create a function called openUrl which you define in each (Android, iOS, etc) project. In your index.html you just load the platform.js file using a relative path.
The implementation can then be platform-specific without ugly device checking.
Comment in phonegap config "res/xml/config.xml"
<access origin=".*" browserOnly="true"/>
by
<!--<access origin="*" browserOnly="true"/>-->
If you allow access, you allow website to be viewed in webview (in this case ALL website).
With no access, all external link are open in native browser.
Use this
window.open('http://www.myurl.nl', '_blank', 'location=yes');

Categories

Resources