You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a workaround for this, but there are a few bits that I don't know how to do yet before submitting a PR.
Questions before a PR
Does anyone know how to put AndroidManifest.xml changes or other res directory changes into a NativeScript plugin?
Summary of problem
Sharing a PDF file to an email seemed to work okay, but sharing it to Adobe Reader or a print service failed. I think the behavior was also different between Android 7 and 10, though I haven't verified that recently.
Solution
Here's code that seems to be working. I think this could work in share-file.android.js with a few tweaks. Notably:
I'm expecting a file:// url only. I think there is existing code to massage file paths and whatnot that should be utilized instead.
I hard-coded application/pdf. The existing code calculates a MIME type, and then ignores it. It should probably be used.
The FileProvider needs a "URI authority". Perhaps this can be automatically based off of the app?
I took out the configurable intent text.
The FileProvider requires changes to AndroidManifest.xml and a new file called file_paths.xml. I don't know how to properly include these changes in a NativeScript plugin. Or do they have to be in the install instructions somehow?
TypeScript
constnewFile=newjava.io.File(newjava.net.URI(url));// the "com.iconcmo.fileprovider" has to match what is in the androidx.core.content.FileProvider section of AndroidManifest.xmlconstfileProviderFile=androidx.core.content.FileProvider.getUriForFile(Application.android.context,"com.iconcmo.fileprovider",newFile);constintent=newandroid.content.Intent(android.content.Intent.ACTION_SEND);intent.setType("application/pdf");intent.addFlags(android.content.Intent.FLAG_GRANT_READ_URI_PERMISSION|android.content.Intent.FLAG_GRANT_WRITE_URI_PERMISSION);intent.putExtra(android.content.Intent.EXTRA_STREAM,fileProviderFile);Application.android.foregroundActivity.startActivity(android.content.Intent.createChooser(intent,"Open file:"));
All of that said, I completely get that this may not be an appropriate thing for this library — feel free to close this issue if so! I also unfortunately only know enough about sharing things on Android to have made the fix above work for the singular purpose of sharing PDFs from my app, but nothing beyond that!
The text was updated successfully, but these errors were encountered:
I have a workaround for this, but there are a few bits that I don't know how to do yet before submitting a PR.
Questions before a PR
Does anyone know how to put
AndroidManifest.xml
changes or otherres
directory changes into a NativeScript plugin?Summary of problem
Sharing a PDF file to an email seemed to work okay, but sharing it to Adobe Reader or a print service failed. I think the behavior was also different between Android 7 and 10, though I haven't verified that recently.
Solution
Here's code that seems to be working. I think this could work in
share-file.android.js
with a few tweaks. Notably:file://
url only. I think there is existing code to massage file paths and whatnot that should be utilized instead.application/pdf
. The existing code calculates a MIME type, and then ignores it. It should probably be used.AndroidManifest.xml
and a new file calledfile_paths.xml
. I don't know how to properly include these changes in a NativeScript plugin. Or do they have to be in the install instructions somehow?TypeScript
AndroidManifest.xml
(inside<application>
tags)file_paths.xml
Resources
All of that said, I completely get that this may not be an appropriate thing for this library — feel free to close this issue if so! I also unfortunately only know enough about sharing things on Android to have made the fix above work for the singular purpose of sharing PDFs from my app, but nothing beyond that!
The text was updated successfully, but these errors were encountered: