Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Open PDF on Android via QDesktopServices::openUrl?
Forum Updated to NodeBB v4.3 + New Features

Open PDF on Android via QDesktopServices::openUrl?

Scheduled Pinned Locked Moved Mobile and Embedded
4 Posts 2 Posters 3.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    digorydoo
    wrote on last edited by
    #1

    I'm working on a Qt app whose target may be Windows desktop or Android. The app largely relies on a web-service that provides data in PDF and other formats. To view a PDF, I first write the data as a local PDF file (QDir::tempPath), then I call QDesktopServices::openUrl to show the file. This works nicely on Windows. On Android, I get the following error in the device's log:

    @
    D/Qt ( 5970): qrc:///PageDebugInfo.qml:551 (getReportCompleted): qml: getReportCompleted: url='file:////data/data/com.company.product/files/com.company.product.tmp.1409758061.pdf'
    D/Instrumentation( 5970): checkStartActivityResult :Intent { act=android.intent.action.VIEW dat=file:////data/data/com.company.product/files/com.company.product.tmp.1409758061.pdf }
    D/Instrumentation( 5970): checkStartActivityResult inent is instance of inent:
    W/System.err( 5970): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=file:////data/data/com.company.product/files/com.company.product.tmp.1409758061.pdf }
    W/System.err( 5970): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1659)
    W/System.err( 5970): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1434)
    W/System.err( 5970): at android.app.Activity.startActivityForResult(Activity.java:3430)
    W/System.err( 5970): at android.app.Activity.startActivityForResult(Activity.java:3391)
    W/System.err( 5970): at android.app.Activity.startActivity(Activity.java:3626)
    W/System.err( 5970): at android.app.Activity.startActivity(Activity.java:3594)
    W/System.err( 5970): at org.qtproject.qt5.android.QtNative.openURL(QtNative.java:116)
    W/System.err( 5970): at dalvik.system.NativeStart.run(Native Method)
    @

    I presume the reason is that I need to declare something in my Android manifest. I studied http://developer.android.com/guide/components/intents-filters.html but I do not seem to be able to figure it out.

    I basically want to show the PDF in the device's default viewer. If there is more than one, the usual dialog to choose a viewer should be shown.

    1 Reply Last reply
    0
    • GianlucaG Offline
      GianlucaG Offline
      Gianluca
      wrote on last edited by
      #2

      Take into account that external activity on Android (even the Android provided activities) cannot read temp files saved in data/data/com.company.product/
      So, maybe the error come out because Android cannot read the file.

      You should write the pdf in an external public directory, like the directory returned by getExternalDir of Android API.

      1 Reply Last reply
      0
      • D Offline
        D Offline
        digorydoo
        wrote on last edited by
        #3

        Thanks for the reply. I'm now using QStandardPaths::writableLocation (QStandardPaths::DownloadLocation) instead of QDir::tempPath. The path is now:

        file:////storage/emulated/0/Download/com.company.product.tmp.1409818898.pdf

        The error is similar:

        @
        checkStartActivityResult :Intent { act=android.intent.action.VIEW dat=file:////storage/emulated/0/Download/com.company.product.tmp.1409818898.pdf }
        D/Instrumentation(21732): checkStartActivityResult inent is instance of inent:
        W/System.err(21732): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=file:////storage/emulated/0/Download/com.company.product.tmp.1409818898.pdf }
        D/dalvikvm(21732): Rejecting registerization due to +iget-object-quick v7, v9, (#8)
        [call stack follows]
        @

        1 Reply Last reply
        0
        • D Offline
          D Offline
          digorydoo
          wrote on last edited by
          #4

          Still not working...

          • I removed the extra slash in file:////.

          • I checked that the pdf file is correctly written in the Download folder and is a valid PDF; it can be opened manually by clicking on it in the Android app "My Files".

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved