How to display a PDF from a phonegap app in Android 8 - android

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.

Related

Can't open PDF file from PWA on Android Device

This is just for the record, since I found the solution.
I experienced an Issue happening only on PWA Standalone App on Androïd device.
I used to open PDF file from my standalone VueJs application with this code :
window.open('<PDF FILE URL>')
or
window.open('<PDF FILE URL>', '_blank')
In that case, the PDF couldn't be read on Android Device. I had this message
Impossible d'afficher le PDF/d'ouvrir
I guess that in english error message would be something like :
Cannot display PDF/Open
Note that in the other side
It works on standard browser (Chrome, Firefox, Internet Explorer)
It works on Apple Device (as PWA)
it works on Windows App (as PWA)
I doesn't work on Android as PWA
My solution was to simply change my code with :
window.location = '<PDF FILE URL>'
My solution was to simply change my code with :
window.location = '<PDF FILE URL>'

NativeScript : How can i open file dialog to select file from my phone

I am Very new in mobile and native script development,
actually i am trying to upload a video file into you tube from my mobile gallery, but before Posting this to you-tube environment, i need a file selector (open file gallery dialog) which will show all videos in my phone
I think there are no plug-in for this.not sure writing native code for this is only option ?? if yes please assist me how??
There might well be a better way, but one approach would be to use the File System Plugin. This way you could enumerate all the files in the documents directory, check if they are videos and then push them to an array e.g.:
var fileArray = [];
var documents = fs.knownFolders.documents();
documents.eachEntity(function (entity) {
console.log(entity.name);
if (entity.name.search('.mpeg') !== -1 {
fileArray.push(entity);
}
// Return true to continue, or return false to stop the iteration.
return true;
});
You then have an array of the file options which you could quite easily build a UI to display. However, I think maybe you want a native UI for the documents system, which I have not come across as yet.
However, contributing the feature to the File System Plugin might not be too difficult.

How to Enabling ckEditor on Android and IPhone Browsers

I'm trying to enable ckeditor on devices like android and iPhone, but didn't show up on any browsers like chrome android browser uc browser opera and safari and also it is showing up on computer browsers?
Download the latest version (default build) of ckeditor
Open ckeditor.js file in notepad (placed at the root of ckeditor folder)
Find the statement:
if(e.webkit)a.indexOf("chrome")>-1?e.chrome=true:e.safari=true;
Add the following statement in front of the above statement:
if(e.chrome)e.mobile=false;
Save and upload it on your server
CKEditor will be working now on your Android Browser
I have followed this step, but still not working on mobile phone browsers?
here the solution of it
here solution for you just need to change or updated you ckeditor.js file to latest ckeditor.js file
here link of latest ckeditor.js
here screenshot
I don't know where did you get those instructions, but they are too complicated and forces you to keep changing the source files whenever you update.
Instead you should follow the official advice at http://docs.ckeditor.com/#!/guide/dev_unsupported_environments
<script src="ckeditor/ckeditor.js"></script>
<script>
CKEDITOR.env.isCompatible = true;
</script>
just add this line in your script then it is working for all devices in
CKEDITOR.env.isCompatible = true;
CKEDITOR.env.isCompatible = true;
CKEDITOR.replace('jobdescription', {
width: '100%',
height: 300
});
refer the below link
https://ckeditor.com/docs/ckeditor4/latest/guide/dev_unsupported_environments.html

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.

Document Viewer for phonegap Applications

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

Categories

Resources