Android Question android 11 sd card android/data folder empty

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Didn't realise but phone (Samsung S10) has moved to Android 11.
Now the folder Android/Data on the SD card shows as empty although there are for sure files in there as I use it to store my SQLite file and the app that is using this is working fine.
With the Total Commander app I can see the folder Android/Data/Files/ and in that folder is my SQLite file, although I am unable to see the contents of the File folder, even with Total Commander.
Is this indeed a problem with Android 11 or could there be a problem with this SD card? I can see other folders on this card fine.

RBS
 

agraham

Expert
Licensed User
Longtime User
It's not a problem it's to do with Android progressively being less permissive about storage access. As you can see the app that owns the data folder can use it but other apps are restricted. This link describes the changes
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
It's not a problem it's to do with Android progressively being less permissive about storage access. As you can see the app that owns the data folder can use it but other apps are restricted. This link describes the changes

Thanks, that is a relief! Will have a look at that link.
So, should my app copy files to that folder then?
So, for example I copy the SQLite file through Windows explorer to to a different folder on the phone and then
(before connecting to the database) let my app copy to SD Card/Android/Data ?

RBS
 
Upvote 0

RB Smissaert

Well-Known Member
Licensed User
Longtime User
Thanks, that is a relief! Will have a look at that link.
So, should my app copy files to that folder then?
So, for example I copy the SQLite file through Windows explorer to to a different folder on the phone and then
(before connecting to the database) let my app copy to SD Card/Android/Data ?

RBS

Got a working solution, but not sure it is the best one:

At the beginning of Main, ActivityCreate:

B4X:
If File.Exists(File.DirRootExternal & "/PhonePats/", "PhonePatsE.db") Then
        Log("Going to copy DB file")
        'File.Copy(File.DirRootExternal & "/PhonePats/", "PhonePatsE.db", Starter.strSD_DB_Dir, "PhonePatsE.db")
        Wait For (File.CopyAsync(File.DirRootExternal & "/PhonePats/", "PhonePatsE.db", Starter.strSD_DB_Dir, "PhonePatsE.db")) Complete (bSuccess As Boolean)
        Log("DB file copied successfully: " & bSuccess)
End If

This is large file, size about 2.1 Gb.
This doesn't run on every app start, so this code is normally commented out.
It does seem to take longer than copying via USB from PC to SD card and a file progress would be nice.

RBS
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
That's what I would have done. For production code I would add a check for the existence of a database file in PhonePats and possibly delete it after copying on the assumption that if one was found it would be an update. I would also add information dialogs to inform the user what's happening.
 
Last edited:
Upvote 0
Top