I've written a client side PDF generation library that will take HTML, turn
it into a PDF file and return that file back to Codename One. showPDF is
the callback invoked when the PDF is generated
//elsewhere
PDFGenerator.generateFromHTML(html, "output.pdf", this::showPdf);
///
private void showPdf(String file) {
Log.p("PDF: " + file);
if
(Display.getInstance().canExecute(FileSystemStorage.getInstance().getAppHomePath()
+ file)) {
Display.getInstance().execute(FileSystemStorage.getInstance().getAppHomePath()
+ file);
}
}
On Android M+ the first time this is called it says "Allow [App Name] to
access photos, media and files on your device?" and regardless of the
answer the app will hang until forced closed as App Not Responding. If the
access is allowed then next time the app is run it works perfectly. If the
access is denied then every time the user get to that point the app will
hang until forced closed.
I wrapped it in that conditional in case that would trigger the permission
prompt and fail at that point to allow it to be requested on the first run,
but it did not.
How can I manage this in a way that doesn't hang. Ideally I need this work
flow:
1. Detect if the permission is granted
2. Ask for permission if it is not available.
3. Only call the execute if the permission has been granted.
Note that this should be really be outside of my library as the user can do
whatever they like with the PDF once its generated (email it, put it in a
web view, share it via a web service), I'm just calling execute as it
allows previewing and sharing natively on iOS and Android - this also
highlights a wider problem of managing permissions for these sorts of
calls.
I also don't really want the solution to be in native code, I want my PDF
library to be simple to use by other people (I've seen questions asked
about how to do this before and I want to release this to the community).
Cheers,
Nick
--
You received this message because you are subscribed to the Google Groups
"CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
Visit this group at https://groups.google.com/group/codenameone-discussions.
To view this discussion on the web visit
https://groups.google.com/d/msgid/codenameone-discussions/d81e4397-bd8b-4c9b-b310-c753fb76ec05%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.