cordova - Can't use pdf.js viewer for local file:// on Android, works on iOS -


using viewer pdf.js managed open local pdf file inappbrowser. following code works without flaws on ios: inappbrowser opens , displays pdf viewer!

window.resolvelocalfilesystemurl(fileurl, function (file) {     window.open('lib/pdf.js-master/web/viewer.html?file=' + file.tourl(), '_blank', 'location=no') }, fail); 

file.tourl() renders file:///blabla/bla.
however, on android pdf fails load, giving console error

"xmlhttprequest cannot load file:///android_asset/www/lib/pdf.js-master/web/locale/locale.properties. cross origin requests supported http.", source: file:///android_asset/www/lib/pdf.js-master/web/viewer.html?file=file:///storage/emulated/0/android/data/xxxxxxxxx/cache/677.pdf 

and there isn't www/lib/pdf.js-master/web/locale/locale.properties file... don't know if has problem, i'm including here.
followed error

"xmlhttprequest cannot load file:///storage/emulated/0/android/data/xxxxxxxxx/cache/677.pdf. cross origin requests supported http.", source: file:///android_asset/www/lib/pdf.js-master/web/viewer.html?file=file:///storage/emulated/0/android/data/xxxxxxxxx/cache/677.pdf 

which absolutely has problem.
resulting in following screen. enter image description here

i don't know how fix error. , once again, works flawlessly on ios! can make work on android? how can enable cross origin requests file:///? problem?
help.

have explicitly enabled webview request files url via javascript?

this works default android api 15 , below. however, default set false api 16 , above, means must call:

setallowfileaccessfromfileurls(true); 

here full example:

// create webview javascript enabled webview mwebview = (webview) findviewbyid(r.id.webview); mwebview.setwebchromeclient(new webchromeclient()); mwebview.getsettings().setjavascriptenabled(true); mwebview.getsettings().setallowfileaccessfromfileurls(true);  // load pdf.js html file correct parameters mwebview.loadurl("file:///android_asset/pdfviewer/..."); 

then make work inappbrowser, add following after line 657 in src/android/inappbrowser.java:

settings.setallowfileaccessfromfileurls(true); 

you can have @ issue different approach override webview settings: building custom webview cordova 5.0 in android


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -