[Interest] Save / load file contents on android
ekke
ekke at ekkes-corner.org
Fri Sep 3 15:53:09 CEST 2021
Am 03.09.21 um 14:51 schrieb Jérôme Godbout:
>
> Take care with the eternal storage opt out will no more be possible
> after November. We will need to target SDK 12 to publish to the store.
> So the 11 opt out flag will no more be possible (November for existing
> application, for new application it’s already started since august).
>
... and thanks to fixed QTBUG-71590 we can target this soon
>
> Try to push an update asap so your user can migrate the data to the
> application proper folder. Other application cannot access the files
> anymore. If your file are already into the application data folder you
> do not have to worry much you still can access them easily.
>
fortunately most of my apps only use data inside application data, but 2
of my apps need access to external storage, so I have to fix this in october
>
> But the QStandard path have work fine for us so far. You can check
> the actual path it resolve to on this page (scroll a bit down to see
> the path for Android):
>
> https://doc.qt.io/qt-5/qstandardpaths.html#StandardLocation-enum
> <https://doc.qt.io/qt-5/qstandardpaths.html#StandardLocation-enum>
>
> *From: *Interest <interest-bounces at qt-project.org> on behalf of ekke
> <ekke at ekkes-corner.org>
> *Date: *Friday, September 3, 2021 at 5:47 AM
> *To: *Nuno Santos <nuno.santos at imaginando.pt>
> *Cc: *Qt Interest <interest at qt-project.org>
> *Subject: *Re: [Interest] Save / load file contents on android
>
> 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 <ekke at ekkes-corner.org
> <mailto:ekke at 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 at qt-project.org <mailto:Interest at qt-project.org>
>
> https://lists.qt-project.org/listinfo/interest <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 at qt-project.org <mailto:Interest at qt-project.org>
> https://lists.qt-project.org/listinfo/interest
> <https://lists.qt-project.org/listinfo/interest>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20210903/83b74d3e/attachment.html>
More information about the Interest
mailing list