Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
It is:
_tempFolder = File.documentsDirectory.resolvePath("PDFs");
Copy link to clipboard
Copied
Did you try that? You mentioned above you are going into File.applicationStorageDirectory.
Copy link to clipboard
Copied
Oops, applicationStorageDirectory is a different thing (and I can't edit the original post), it is using documentsDirectory which is resolving to /storage/emulated/0/
Copy link to clipboard
Copied
OK, so it turns out, the problem is crossing the border to API 24, Android stopped supporting passing local files to other applications via a file:// url, instead requiring a content:// url via a FileProvider which requires a native extension.
Copy link to clipboard
Copied
OK, this is weird.
I had to compile using Java 1.7 or the debug tool wouldn't recognise the classes.
I'm pretty sure the package has no idea the file_paths.xml even exists, though the platform.xml does appear to be correct and in the right place.
I had to comment out the...
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="air.PdfTest.provider"
android:exported="false"android:grantUriPermissions="true">
<meta-dataandroid:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"/>
</provider>
... part from the manifest (under <application>, just as the docs say), or the app would just "stop" immediately after starting.
I then had to copy the FileProvider.class files into the jar file to package with the ANE, otherwise execution would simply exit on FileProvider.getUriForFile because it didn't find it on the device?
And that works. Despite the fact that it now isn't declaring a provider at all, let alone telling it where the folder paths are, and I had to package the one part of the API this ANE exists to use, myself. Wow.
I'm not going to mark this thread as answered because there has got to be something wrong with this process.
Copy link to clipboard
Copied
Sorry for the late responses, it's been err, seasonal..
I always used Adobe Native Extensions. That's what they're designed for. To nearly unlimitedly extend AIRSDK on platforms using native code. I used to use a docLauncher.ane and I purchased it so I could have the source code and update it how I saw fit. I have the ANE, I just can't find the source ANE to see what is assured to be a different intent these days.
I do see other plugins that offer this and a wide variety of other capabilities. It's always your job to take a look at the updated version and test it out if possible with any code you find. I'd recommend solutions that have the correct license and grant you source code so you can read/modify it.
Sometimes the tiny cost is entirely worth not losing days worth of time. I myself like to dig in and figure it out but I've used Java and AndroidSDK before. For this issue, if you don't know Java/AndroidSDK or the ANE process, I'd suggest you decide if that's what you want to do. If so, there are unlimited video and tutorial resources out there to help and feel free to come back with any very specific questions!
Copy link to clipboard
Copied
I've actually managed to solve a few of the issues. I've got the <provider> node in there without it crashing, but it's not loading the file paths. My file says this:
<files-path name="files" path="." />
<cache-path name="cache" path="." />
<external-path name="external" path="." />
<external-files-path name="ext-files" path="." />
<external-cache-path name="ext-cache" path="." />
<external-media-path name="ext-media" path="." />
But when it loads (I used a copy of the FileProvider source to output Trace commands), it only contains this:
<cache-path name="Pictures" path="." />
This means no matter what I put in the <meta-data> node, or even if it's not there, it's always loading some default paths file that isn't part of the package, and the only files I can launch have to be in cache.
I've followed the same pattern as other ANEs I've seen, so the file is outside the .jar, under {extensionID}-res/xml/file_paths.xml and the platform.xml has the packagedResource linking that folderName to the packageName of the extensionID. And that folder is then packaged under Android-ARM with the jar and the library and platform, so it is there.
That's the only hold-up right now. If I can get this solved, I'll have the means to make whatever ANEs I want.