Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Unsolved How to save files under Android/data?

    Mobile and Embedded
    2
    4
    584
    Loading More Posts
    • 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
      Bremenpl last edited by

      Hello there,
      I am developing an Android application using Qt 5.13.0. Using the https://doc.qt.io/qt-5.9/qstandardpaths.html I am tryng to figure out which path will lead me to the Android/data directory:

      0_1567496011020_3459201c-1787-43bd-af62-d127f9927d60-image.png

      I have set the package name in the android manifest file to com.company.appname.
      I would appreciate all help.

      lprzenioslo.zut.edu.pl

      Pradeep P N 1 Reply Last reply Reply Quote 1
      • Pradeep P N
        Pradeep P N @Bremenpl last edited by Pradeep P N

        Hi @bremenpl

        Can you please check QStandardPaths & enum QStandardPaths::StandardLocation.

        namespace {
        
        void createAppFolder(const QString &folder)
        {
            QDir dir(folder);
            dir.mkpath(".");
        }
        }
        
        
        QString defaultFolderPath()
        {
            const QString path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
            if (!QFileInfo::exists(path))
                createAppFolder(path); 
            return path;
        }
        

        All the best.

        Pradeep Nimbalkar.
        Upvote the answer(s) that helped you to solve the issue...
        Keep code clean.

        B 1 Reply Last reply Reply Quote 2
        • B
          Bremenpl @Pradeep P N last edited by Bremenpl

          @pradeep-p-n Hi, thanks for answer,
          I have already tried QStandardPaths::AppDataLocation enum value. It places the file in a location that is not accessible to the user (/data). Instead, I am looking for an enum that would access /storage/emulated/0/Android/data, since this path is accessible "outside" the application.

          lprzenioslo.zut.edu.pl

          1 Reply Last reply Reply Quote 0
          • B
            Bremenpl last edited by Bremenpl

            With these piece of code I have checked all the available locations:

            qDebug() << "Config path set to:" << configPath;
            for (int i = 0; i <= static_cast<int>(QStandardPaths::AppConfigLocation); i++)
            {
            	const QString tmp = QStandardPaths::writableLocation(static_cast<QStandardPaths::StandardLocation>(i));
            	qDebug() << "Path" << i << tmp;
            }
            

            Seems like Qt cannot save the file where I need to:

            Path 0 "/data/user/0/org.qtproject.example.mri/files"
            Path 1 "/storage/emulated/0/Documents"
            Path 2 ""
            Path 3 ""
            Path 4 "/storage/emulated/0/Music"
            Path 5 "/storage/emulated/0/Movies"
            Path 6 "/storage/emulated/0/Pictures"
            Path 7 "/data/user/0/org.qtproject.example.mri/cache"
            Path 8 "/data/user/0/org.qtproject.example.mri/files"
            Path 9 "/data/user/0/org.qtproject.example.mri/files"
            Path 10 "/data/user/0/org.qtproject.example.mri/cache"
            Path 11 "/storage/emulated/0"
            Path 12 "/data/user/0/org.qtproject.example.mri/cache"
            Path 13 "/data/user/0/org.qtproject.example.mri/files/settings"
            Path 14 "/storage/emulated/0/Download"
            Path 15 "/data/user/0/org.qtproject.example.mri/cache"
            Path 16 "/data/user/0/org.qtproject.example.mri/files/settings"
            Path 17 "/data/user/0/org.qtproject.example.mri/files"
            Path 18 "/data/user/0/org.qtproject.example.mri/files/settings"
            

            Any ideas?

            lprzenioslo.zut.edu.pl

            1 Reply Last reply Reply Quote 0
            • First post
              Last post