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. Programatically iterate over public Files in Android
Qt 6.11 is out! See what's new in the release blog

Programatically iterate over public Files in Android

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
5 Posts 3 Posters 240 Views
  • 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.
  • B Offline
    B Offline
    beku2
    wrote last edited by
    #1

    I want to read several public folders on a Android SDK34 device and use the content to build a app internal DB. Examples are the DCIM folder, Documents or Downloads. Which non interactive Qt file access APIs might help with that task?

    The Qt-6.11.1 Application has in CMakeLists.txt following permissions:
    QT_ADD_ANDROID_PERMISSION( ${PROJECT_NAME}
    NAME android.permission.READ_INTERNAL_STORAGE
    android.permission.WRITE_INTERNAL_STORAGE
    android.permission.READ_EXTERNAL_STORAGE
    android.permission.WRITE_EXTERNAL_STORAGE
    android.permission.READ_MEDIA_IMAGES
    android.permission.READ_MEDIA_AUDIO
    android.permission.READ_MEDIA_VIDEO
    android.permission.INTERNET
    )

    The QML FileDialog, which is not programatical, does see all files very nicely. It probably uses SAF or MediaStorage according to a post from 2023. What is the current stage of support. Which API allows to use that in a programatic way?

    For the record: QStandardPaths::standardLocations(type) returns only app specific paths.

    Before the QML FileDialog I tried without much luck:
    The old Android QtAndroidPrivate::requestPermissions() are gone. Even though it is mentionened in the private header file
    <QtCore/private/qandroidextras_p.h>, this symbol is not resolved by the linker on arm64-v8a using Qt Creator 20.0.0 (RH Linux)
    /opt/android-sdk/ndk/27.2.12479018/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=aarch64-none-linux-android32
    ld.lld: error: undefined symbol: requestPermissionsInternal(QList<QString> const&)

    jsulmJ 1 Reply Last reply
    0
    • B beku2

      I want to read several public folders on a Android SDK34 device and use the content to build a app internal DB. Examples are the DCIM folder, Documents or Downloads. Which non interactive Qt file access APIs might help with that task?

      The Qt-6.11.1 Application has in CMakeLists.txt following permissions:
      QT_ADD_ANDROID_PERMISSION( ${PROJECT_NAME}
      NAME android.permission.READ_INTERNAL_STORAGE
      android.permission.WRITE_INTERNAL_STORAGE
      android.permission.READ_EXTERNAL_STORAGE
      android.permission.WRITE_EXTERNAL_STORAGE
      android.permission.READ_MEDIA_IMAGES
      android.permission.READ_MEDIA_AUDIO
      android.permission.READ_MEDIA_VIDEO
      android.permission.INTERNET
      )

      The QML FileDialog, which is not programatical, does see all files very nicely. It probably uses SAF or MediaStorage according to a post from 2023. What is the current stage of support. Which API allows to use that in a programatic way?

      For the record: QStandardPaths::standardLocations(type) returns only app specific paths.

      Before the QML FileDialog I tried without much luck:
      The old Android QtAndroidPrivate::requestPermissions() are gone. Even though it is mentionened in the private header file
      <QtCore/private/qandroidextras_p.h>, this symbol is not resolved by the linker on arm64-v8a using Qt Creator 20.0.0 (RH Linux)
      /opt/android-sdk/ndk/27.2.12479018/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=aarch64-none-linux-android32
      ld.lld: error: undefined symbol: requestPermissionsInternal(QList<QString> const&)

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote last edited by
      #2

      @beku2 On C++ side you can use https://doc.qt.io/qt-6/qdiriterator.html to iterate over files/folders.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • B Offline
        B Offline
        beku2
        wrote last edited by
        #3

        QDir -> QFileInfoList and QDirIterator show mostly app dirs and files and some public dirs without file names.

        1 Reply Last reply
        0
        • B Offline
          B Offline
          beku2
          wrote last edited by
          #4

          The flow in my app is like:
          Android SDK 34 -> QML-> check permission -> if not: show reason why as text and ask for agreement -> requestPermission() (now copied from Qt sources into my app_data.cpp)

          debug output in QtCreator:
          I/app_data.cpp:506 requestPermissionsInternal(): after AndroidDeadlockProtector
          I/app_data.cpp:513 requestPermissionsInternal(): after promise->start()
          I/app_data.cpp:476 nextRequestCode(): code:225
          I/app_data.cpp:519 requestPermissionsInternal(): after locker.unlock()
          I/app_data.cpp:529 operator()(): perm:android.permission.MANAGE_EXTERNAL_STORAGE
          I/app_data.cpp:543 requestPermissionsInternal(): after releaseAndroidDeadlockProtector
          I/app_data.cpp:632 requestPermissions(): after oyjlArgsQmlRequestPermissions(android.permission.MANAGE_EXTERNAL_STORAGE)
          I/app_data.cpp:537 operator()(): after activity().callMethod requestCode:225
          W/default : Found no valid pending permission request for request code 225

          ... the app is keeps frozen after (QFuture result; ...) result.waitForFinished();

          1 Reply Last reply
          0
          • Nils SjobergN Offline
            Nils SjobergN Offline
            Nils Sjoberg
            wrote last edited by
            #5

            Give up the extensive MANAGE_EXTERNAL_STORAGE permission (which is stuck because it doesn't have proper callback wiring in Qt) and instead use SAF (ACTION_OPEN_DOCUMENT_TREE with takePersistableUriPermission) for one-time folder selection, or the MediaStore API if it's just media 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