Skip to main content
Participating Frequently
November 22, 2018
Question

Launch a local PDF file in Android 26

  • November 22, 2018
  • 1 reply
  • 3777 views

Hello Internet,

We have an app that is supposed to be able to open PDF files in their default viewer in either Desktop, Android or iOS.

It does this by copying the file from within File.applicationDirectory (or generating it internally) into File.applicationStorageDirectory, then taking the new path and making the appropriate call. In the case of Android, it would work so:

var request : URLRequest = new URLRequest(target.url);

//this is a workaround (bug introduce in new sdk)

//https://bugbase.adobe.com/index.cfm?event=bug&id=3759971

request.contentType = "text/plain";

navigateToURL(request);

and then delete the file when it was done. I don't know what bug the comment is referring to, the url is a 404.

Recently I've had to make a change for Android to use the new permission system. This works so:

And the app asks for permission before successfully launching the PDF file in its associated viewer.

Even more recently, Google Play requires targetSdkVersion="26", and now even once it has obtained permission, navigateToURL does nothing. I also tried StageWebView and got a blank screen on swv.loadURL(target.url), and target.openWithDefaultApplication() throws an exception saying it can't find the file (even though it's right there and target.exists = true). I can find the file through the file browser app, and launch it from there just fine.

Any ideas how I can fix this? Do I need to alter the url in some way?

target.url = file:///storage/emulated/0/PDFs/Doc_EA21E1DB-E8F1-D8BC-DC78-3CE973A98E3E.pdf

target.nativePath = /storage/emulated/0/PDFs/Doc_EA21E1DB-E8F1-D8BC-DC78-3CE973A98E3E.pdf

This topic has been closed for replies.

1 reply

sinious
Legend
November 27, 2018

Just as a quick fix, try putting it in the public documents folder so you can be assured it's not a file permission issue.

pzahraAuthor
Participating Frequently
November 28, 2018

It is:

_tempFolder = File.documentsDirectory.resolvePath("PDFs");

sinious
Legend
November 28, 2018

Did you try that? You mentioned above you are going into File.applicationStorageDirectory.