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. I have a question about Android file permissions in QT
Forum Updated to NodeBB v4.3 + New Features

I have a question about Android file permissions in QT

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
1 Posts 1 Posters 259 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.
  • R Offline
    R Offline
    rhaps29
    wrote on 5 Dec 2023, 04:42 last edited by
    #1

    Now, I am trying to make android mp3 application using qt

    I wrote source code below.

    QString path1 = "/storage/emulated/0";
    QDirIterator it(path1, QStringList() << "*.mp3", QDir::Files, QDirIterator::Subdirectories);
    while (it.hasNext()) {
        it.next();
        listWidget->addItem(it.fileName());
    }
    

    but It did not work. So I think that I need the file Permissions.

    I tried what I can everythings.

    I use source code below. It worked before one years ago but It did not work now.

    bool checkPermission()
    {
        auto r=    QtAndroidPrivate::checkPermission(QStringLiteral("android.permission.READ_EXTERNAL_STORAGE")).result();
        if (r == QtAndroidPrivate::Denied)
        {
            r = QtAndroidPrivate::checkPermission(QStringLiteral("android.permission.READ_EXTERNAL_STORAGE")).result();
            if (r == QtAndroidPrivate::Denied)
                return false;
        }
        return true;
    }
    

    *QStringLiteral("android.permission.READ_EXTERNAL_STORAGE") this part was QtAnroidPrivate::Storage. I edited my source code becuase QtAndroidPrivate::Storage is deprecated.

    After a lot of research, I found an article that says that from Android 13 onwards, users doesn't need to request file permissions.

    How to access external storage(sdcard/usb) in an android device in a qt qml based application?

    and

    QFileDialog::getOpenFileName(this, tr("Open File"), QDir::rootPath(), tr("Music (*.mp3)"));
    

    The above source code works fine without file permissions.

    I have a question, I would like to know why the code I wrote does not work.

    QString path1 = "/storage/emulated/0";
    QDirIterator it(path1, QStringList() << "*.mp3", QDir::Files, QDirIterator::Subdirectories);
    while (it.hasNext()) {
        it.next();
        listWidget->addItem(it.fileName());
    }
    

    Please give me a hint. Thanks

    1 Reply Last reply
    0

    1/1

    5 Dec 2023, 04:42

    • Login

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