[Android-development] QDesktopServices::openUrl in Qt 5.15
Sandro Andrade
sandroandrade at kde.org
Thu May 7 03:43:30 CEST 2020
Hi there,
With latest Android changes for user storage handling, I've noticed
that QDesktopServices::openUrl() now checks for Uri's with valid
permissions in Android.
My case is as follows:
1) I download a remote PDF file into the
QStandardPaths::writableLocation(QStandardPaths::DownloadLocation)
directory
2) Call QDesktopServices::openUrl() to view PDF file using some
Android system viewer
This worked fine in previous Qt for Android releases. With Qt 5.15 it
fails with a "openURL(): No permissions to open Uri" message,
generated by QtNative::openURL(), since no Uri permissions are found.
I tried to add Uri permissions like the ones presented in
https://codereview.qt-project.org/gitweb?p=qt%2Fqtbase.git;a=commit;h=dcb38e4bc74337d0d670bc30b8193cbd73f11599
I basically invoke a JNI method which does the following:
Uri uri = Uri.parse(fileName);
activity.getContentResolver().takePersistableUriPermission(uri,
Intent.FLAG_GRANT_READ_URI_PERMISSION |
Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
But invoking takePersistableUriPermission fails with a:
java.lang.SecurityException: No persistable permission grants found
for UID 10632 and Uri
file:///emulated/0/Download/historico-escolar-parcial.pdf
I also tried to store the downloaded PDF file in
QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) with
no success.
Any hints on how to properly grant Uri permissions for downloaded files?
Thanks in advance,
--
Sandro
More information about the Android-development
mailing list