native.showWebPopup shows PDFs in simulator but not on Android device

Hi!

I’m almost done with a tabbed app, one that should give easy access to a handful of documents.

Right now I’m using native.showWebPopup() pointed to the online document, but having the documents packaged with the app would be acceptable in this case, if it solves the problem.

The problem I’m having is that the PDFs show up fine with zoom buttons etc in the Simulator, both for Iphone and Android. But on my Sony Xperia Z, I get a blank view and no crash.

There’s not much code to share, I just call it with a URL like this:

native.showWebPopup(0, T, \_CW\*2, \_CH\*2-50-T, "http://avia.se/iphone/test/Checklista.pdf")  

A normal URL like this one works fine with the same code on the device: 

http://avia.se/iphone/test/Klasser.html  

What I’m asking is whether there’s a widget or other solution, or which of the workarounds I’ve seen is the correct one to use at present, to cater to (preferably) Android OS 2.3.5 and up, Iphone OS 4.3 and up. I’m using Corona 2013.1076.

Hi @henrik5,

Just out of curiosity, could you try this using the newer “newWebView” method, versus “showWebPopup”?

http://docs.coronalabs.com/api/library/native/newWebView.html

No dice. Same behavior as described above. (Edit: editing the post to remove a word stripped newlines from the code formatted text. I tried to restore it as best I could.)

 

webView = native.newWebView( 0, T, \_CW\*2, \_CH\*2-50-T ) -- webView:request( "http://avia.se/iphone/test/"..dokumentlankar[row]..".pdf" ) webView:request( "http://avia.se/iphone/test/Klasser.html" ) webView:addEventListener( "urlRequest", webListener ) --...code after this to change a newText title is not executed or doesn't take effect... end local function webListener( event ) if event.url then print( "You are visiting: " .. event.url ) end if event.type then print( "The event.type is " .. event.type ) -- print the type of request end --if event.errorCode then native.showAlert( "Error!", event.errorMessage, { "OK" } ) --end end

The showAlert does not pop up. Zoom buttons are displayed.

It could be that some default is set to download pdfs instead of viewing them in the browser, because that’s what it does in Chrome. If so, how do I change the behavior in my app?

Other Android apps display PDFs fine, with a webChromeClient.

The Sony Xperia Z has Ice Cream Sandwich.

Android web views cannot render PDFs.  But you can request the operating system to display the PDF in its default viewer as follows.

system.openURL("http://www.mydomain.com/my.pdf")

You can also display PDFs via your Android device’s default PDF viewer as follows.  What’s nice with this solution is that the Back button will bring you back to your app.

local pdfPath = system.pathForFile("my.pdf") system.openURL(pdfPath)

Hi @henrik5,

Just out of curiosity, could you try this using the newer “newWebView” method, versus “showWebPopup”?

http://docs.coronalabs.com/api/library/native/newWebView.html

No dice. Same behavior as described above. (Edit: editing the post to remove a word stripped newlines from the code formatted text. I tried to restore it as best I could.)

 

webView = native.newWebView( 0, T, \_CW\*2, \_CH\*2-50-T ) -- webView:request( "http://avia.se/iphone/test/"..dokumentlankar[row]..".pdf" ) webView:request( "http://avia.se/iphone/test/Klasser.html" ) webView:addEventListener( "urlRequest", webListener ) --...code after this to change a newText title is not executed or doesn't take effect... end local function webListener( event ) if event.url then print( "You are visiting: " .. event.url ) end if event.type then print( "The event.type is " .. event.type ) -- print the type of request end --if event.errorCode then native.showAlert( "Error!", event.errorMessage, { "OK" } ) --end end

The showAlert does not pop up. Zoom buttons are displayed.

It could be that some default is set to download pdfs instead of viewing them in the browser, because that’s what it does in Chrome. If so, how do I change the behavior in my app?

Other Android apps display PDFs fine, with a webChromeClient.

The Sony Xperia Z has Ice Cream Sandwich.

Android web views cannot render PDFs.  But you can request the operating system to display the PDF in its default viewer as follows.

system.openURL("http://www.mydomain.com/my.pdf")

You can also display PDFs via your Android device’s default PDF viewer as follows.  What’s nice with this solution is that the Back button will bring you back to your app.

local pdfPath = system.pathForFile("my.pdf") system.openURL(pdfPath)