I just tried opening a PDF file from my app's "system.ResourceDirectory" and was able to successfully display it on the following devices:
- Samsung Galaxy SII (Android 2.3)
- Nook Color (Android 2.2)
- Samsung Galaxy Nexus (Android 4.0.4)
The trick is to open the PDF as follows...
That is, you'll need to call
on your PDF file when feeding it to the
I also have to retract the statement I made up above. Most Android devices do in fact come with a PDF viewer. Although, I've found different viewers on different devices. So, it still may be possible that some Android device manufacturers may not include a PDF viewer.
So, to help your code recognize if the device supports displaying the given file, we've modified our Android code today to have
return false if the OS is unable to open the given URL. This also matches the iOS/Mac behavior that was implemented last December. This code change will be made available in daily build #1016, tomorrow.
This means your can write your code like this...
local wasOpened = system.openURL(system.pathForFile("MyDocument.pdf"))if wasOpened == false then -- Display a message to the user to install a PDF viewer app.end
I hope this helps!
uid: 32256 topic_id: 35318 reply_id: 140414