How to open file with default application on Android (SDK 23 and above) using QDesktopServices

  • Hi,
    I try to open pdf file with default application on Android (SDK 23 or above) using QDesktopServices like that (old code):

    QDesktopServices desk;

    I know that file:// prefix is not allowed anymore.
    We should send the URI through content:// scheme instead.
    I don't understand how implement this feature.
    This code:

    QDesktopServices desk;

    opens the default application, but the file is not loaded.

    Qt 5.13.1 (QFile works as expected).
    NDK 19c
    Android 9.0


  • Setting up FileProvider seems a lot of unnecessary somewhat complicated (for people who visit the Java side every two years...) work for keeping old apps running. Today I ran into a piece of Java code that enables openUrl:

    public static void allowUriSchemes() {
            if (android.os.Build.VERSION.SDK_INT >= 23) {
                // Regular file:// is disabled
                try {
                    final Method m = StrictMode.class.getMethod("disableDeathOnFileUriExposure");
                } catch (final Exception e) {}

  • @mvuori Where did you wrote this code can you guide me please, I'm new to Qt andriod

Log in to reply