QDir::entryList only shows todays files
-
I have this code to run on on Android:
QDir dir(path); const auto files = dir.entryList({"SPIRAL_*.json"}, QDir::Files, QDir::Time);When I run this on a phone with Android 9 then I get all "SPIRAL_*.json" files that are present in the directory 'path'.
When I run this on a phone with Android 13 then I get only all "SPIRAL_*.json" files with modification date of today. When I look on the phone itself I can see that there are more files on older dates.
Any idea what's going wrong here and how to fix it?
-
I have this code to run on on Android:
QDir dir(path); const auto files = dir.entryList({"SPIRAL_*.json"}, QDir::Files, QDir::Time);When I run this on a phone with Android 9 then I get all "SPIRAL_*.json" files that are present in the directory 'path'.
When I run this on a phone with Android 13 then I get only all "SPIRAL_*.json" files with modification date of today. When I look on the phone itself I can see that there are more files on older dates.
Any idea what's going wrong here and how to fix it?
@Michel-de-Boer perhaps this is caused by Android changing access to file storage.
Qt just has fixed many things with QFile, QDir, ...
https://www.qt.io/blog/qt-for-android-storage-updates -
@Michel-de-Boer perhaps this is caused by Android changing access to file storage.
Qt just has fixed many things with QFile, QDir, ...
https://www.qt.io/blog/qt-for-android-storage-updates@ekkescorner Thanks for your reply. I think you are right. My observation that it only returned today's files was wrong. It only returns the files that have been created by the particular app instance itself!
What a mess the made of it.
The directory is a public directory obtained byEnvironment.getExternalStoragePublicDirectoryAs a test I just tried with Java to see what I get with this:
File[] files = path.listFiles(); // path is a subdir in the external storage public dirI get the same issue. Only files created by the current app instance itself. I had a mix of files created by a debug version and a released version from the app store.
Even if I uninstall my official released version from the app store and then re-install from the app store, then with the re-installed version I cannot see the files created by the previous install anymore. And the files I really there when I look in the directory (with adb or a file manager). -
@ekkescorner Thanks for your reply. I think you are right. My observation that it only returned today's files was wrong. It only returns the files that have been created by the particular app instance itself!
What a mess the made of it.
The directory is a public directory obtained byEnvironment.getExternalStoragePublicDirectoryAs a test I just tried with Java to see what I get with this:
File[] files = path.listFiles(); // path is a subdir in the external storage public dirI get the same issue. Only files created by the current app instance itself. I had a mix of files created by a debug version and a released version from the app store.
Even if I uninstall my official released version from the app store and then re-install from the app store, then with the re-installed version I cannot see the files created by the previous install anymore. And the files I really there when I look in the directory (with adb or a file manager).@Michel-de-Boer yep. this decision made by Google makes it much more difficult to deal with files.
take a look at https://bugreports.qt.io/browse/QTBUG-98974 -
@Michel-de-Boer yep. this decision made by Google makes it much more difficult to deal with files.
take a look at https://bugreports.qt.io/browse/QTBUG-98974@ekkescorner I will go for private app storage with android:hasFragileUserData="true" in the android manifest. My reason for using public storage before is to protect user stored data from being deleted during a re-install of the app.
Private storage still allows the simplicity of use an ordinary filesystem. SAF is too complicated for my needs with the content and tree URIs. It also makes the user experience cumbersome. Mediastore does not apply to my case as I deal with json files associated with a thumbnail picture (I handle 2 files as a single logical entity).
IMHO the file handling in Android seems broken. I can write with my app in public space, but after a re-install I cannot read the files I have written before. That does not make sense.
It must be hard for Qt to deal with this model in a system-independent way. -
@ekkescorner I will go for private app storage with android:hasFragileUserData="true" in the android manifest. My reason for using public storage before is to protect user stored data from being deleted during a re-install of the app.
Private storage still allows the simplicity of use an ordinary filesystem. SAF is too complicated for my needs with the content and tree URIs. It also makes the user experience cumbersome. Mediastore does not apply to my case as I deal with json files associated with a thumbnail picture (I handle 2 files as a single logical entity).
IMHO the file handling in Android seems broken. I can write with my app in public space, but after a re-install I cannot read the files I have written before. That does not make sense.
It must be hard for Qt to deal with this model in a system-independent way.@Michel-de-Boer thx for your info.
never used hasFragileUserData before - it's now on my TODO to take a look at this.
have two apps where I have to deal with scoped storage - looking forward how well the Qt impl in 5.15.13 is done - testing 5,15,13 this week -
M Michel de Boer has marked this topic as solved on