Hi Nuno,

Am 03.09.21 um 11:05 schrieb Nuno Santos:
Ekke,

I have been experiencing some inconsistencies with Android file access using QStandardPaths, mostly now that I’m preparing the ground for Android 11 support. From Android 11 onwards, there will be changes in the way an app can access filesystem resources.

This problem started when one of apps was in some systems using legacy file access while in others was already using the new storage approach. In order to temporary fixes this issues I have set the requestLegacyExternalStorage to true, however, soon this will end as in Android 11 it will be ignored.

I'm in the same situation as you ;-) have set requestLegacyExternalStorage ATM

last weeks had much work moving all my projects from Qt 5.13.2 to 5.15.5, so I can prepare for Qt 6.2

now there will be 3 weeks vacation

then support of Android 11 file storage will be high on my TODO list

... and hoping then to find some docs / tips HowTo support this from Qt ;-)

ekke


One of the current challenges I’m facing the moving/copying resources from legacy storage to new storage when using QStandardPaths and QFileDialog.

How have you been handling Android 11 support and data migration from older versions?

Are you able to do it just with Qt stuff or do you need to handle some of the things with native android API’s?

Thanks!

Nuno

On 31 Aug 2021, at 13:38, ekke <e...@ekkes-corner.org <mailto:e...@ekkes-corner.org>> wrote:

Am 31.08.21 um 14:12 schrieb Wilhelm Meier via Interest:
Hi all,

does anybody have a minimum working example how to load / save json file
contents (auscii contents) to / from a file on android.

I made several attempts, but I get weird filenames and I'm not able to
load the stored file.

thx
_______________________________________________
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest
Hi, some snippets HowTo save a JSON. use QVariantMap for a JSON Object or QVariantList for JSON Array   QJsonDocumentjda =QJsonDocument::fromVariant(myQVariantMap);
QByteArraybuffer=jda.toJson();
saveTestFile("_my_test.json",buffer);
...

voidDataServer::saveTestFile(constQString&fileName,constQByteArray&buffer)
{
QStringfilePath=mDataManager->dataPath(fileName);
QFilesaveFile(filePath);
if(!saveFile.open(QIODevice::WriteOnly)){
qWarning()<<"Couldn't open file to write "<<filePath;
return;
}
qint64bytesWritten=saveFile.write(buffer);
saveFile.close();
qDebug()<<"Bytes written: "<<bytesWritten<<" to: "<<filePath;
}
....

//Android:AppDataLocationworksoutofthebox,iOSyoumustcreatetheDIRfirst!!
mDataRoot=QStandardPaths::standardLocations(QStandardPaths::AppDataLocation).value(0);
mDataPath=mDataRoot+"/data/";
----
and reading is similar

jda=QJsonDocument::fromJson(dataFile.readAll());
dataFile.close();
if(!jda.isArray()){
myMap =jda.toVariant().toMap();
} else {
        myList=jda.toVariant().toList();
     }
-----
hope it helps
_______________________________________________
Interest mailing list
Interest@qt-project.org <mailto:Interest@qt-project.org>
https://lists.qt-project.org/listinfo/interest <https://lists.qt-project.org/listinfo/interest>


_______________________________________________
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest

Reply via email to