Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt and app data storage in Android

I am working on a mobile app, using Qt/C++, right now focusing on Android. My app needs to store some permanent data, in a private and secure way (not accessible to other apps, protected as much as possible):

  • some basic key/value settings: QSettings seems to be what I need here. The question being where does this end up in Android, is it stored in the shared preferences section?
  • binary files, such as a few pics (these are created by the app, not static resources). I would have stored this in an internal storage file; where would I store this in Qt? Do I use Qt's file capabilities, and java calls to find my app's internal storage folder, or is there a Qt object designed for that?

Thanks.

like image 362
Will59 Avatar asked May 20 '18 18:05

Will59


People also ask

Where are app data stored in Android?

When you install an app (either from the Google Play Store or through a downloaded apk file), Android places that into the device's app folder. That's /data/app/your_package_name for most apps. Some encrypted apps use /data/app-private/your_package_name.

Can QT be used for Android?

Qt for Android enables you to develop Qt applications for Android devices, and supports a wide range of features and use-cases. To download and install Qt for Android, follow the instructions on the Getting Started with Qt for Android page. To build Qt from source, see Building from Source.

What is the best way to store data in Android?

You can use external storage if the data that your application stores can be used by other applications. Additionally, if the file stored by your application is huge, such as a video, you can save it to external storage. You can use external storage to keep the data even after uninstalling the application.

What is app data storage?

App data is the data that is downloaded or generated as part of a device's content - for instance, downloaded books or music, while cache files are temporary files many programs generate while in use, such as saved portions of websites you visit in a browser.


1 Answers

Android maintains a standard storage for applications under the path /data/user/0 , where each application gets storage space. so if you have an application named org.qtproject.example.myApp, Android automatically creates storage space for this app:

/data/user/0/org.qtproject.example.myApp

The settings are stored under the files folder of this path, as ../files/.config/OrganizationName/AppName.conf

When you want to store information in Android you don't use absolute paths, instead you specify the location of your storage using Qt QStandardPaths which usually returns location under the application path mentioned above, so for example to store a file mySomeFile, you would set the path using QStandardPaths like:

auto path = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
auto fileName= path + "/mySomeFile";

and the file is stored as :

/data/user/0/org.qtproject.example.myApp/files/mySomeFile
like image 194
Mohammad Kanan Avatar answered Oct 22 '22 00:10

Mohammad Kanan