Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to save files under Android/data?



  • 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.



  • 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-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.



  • 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?


Log in to reply