Android Question targetSdkVersion=30 and File.DirRootExternal

Status
Not open for further replies.

Scantech

Well-Known Member
Licensed User
Longtime User
I read
Note that you need to reference android.jar from android-29 folder.
It will not work with targetSdkVersion=30. Avoid using File.DirRootExternal. Either use File.DirInternal or RuntimePermissions.GetSafeDirDefaultExternal.

Does that mean in the future we can't use File.DirRootExternal? Will there be a workaround just like the manifest for targetSdkVersion=29?
 

mcqueccu

Well-Known Member
Licensed User
Longtime User
The Workaround is exactly on top of what you quoted above...
B4X:
SetApplicationAttribute(android:requestLegacyExternalStorage, true)

 
Upvote 0

Scantech

Well-Known Member
Licensed User
Longtime User
The way i read it "will not work with targetSdkVersion=30" and "Avoid using File.DirRootExternal" Why avoid using File.DirRootExternal? I have been using it for 11 years and it is far better option then others. The data is not deleted when application is uninstalled with File.DirRootExternal. If its annoying to add dangerous permission then avoid it.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
There will not be a simple, transparent workaround for this. It will require the user to explicitly select the folder, as done with ExternalStorage class.
The data is not deleted when application is uninstalled with File.DirRootExternal.
Not sure that most users will be happy with apps leaving files after they are uninstalled. Anyway, this is not our call.
 
Upvote 0

divinglog

Member
Licensed User
Longtime User
There will not be a simple, transparent workaround for this. It will require the user to explicitly select the folder, as done with ExternalStorage class.

Not sure that most users will be happy with apps leaving files after they are uninstalled. Anyway, this is not our call.

I'm actually facing the same problem. My app allows users to store personal logbook data which is stored in SQLite database files which are currently located in a separate folder in the root of the phone storage. I often hear from users when they are facing a problem with the app, the first thing they do is uninstalling and reinstalling the app. Of course this does not fix any app problems, but this is the first thing most users do. But now all their personal database files would be gone if I use "GetSafeDirDefaultExternal" instead of File.DirRootExternal & "/App Name".

The logbook files contain personal data entered by users by hand, which is a LOT of work. Even if users uninstall the app, they expect that this data is not lost. As far as I understand, using SQLite databases with ExternalStorage class does not work, right?

So my only solution I'm planning for now is copying the databases into GetSafeDirDefaultExternal folder before setting targetSdkVersion=30 next year and implementing some kind of "Backup" function that let users pick a backup folder using the ExternalStorage class and copying the database to this folder when the app is closed.

Better would be an external folder that can be used with normal File apis and SQLite databases that is not removed when the app is uninstalled. But as far as I understand, there is no folder like this starting with Android 11 (API 30)
 
Last edited:
Upvote 0
Status
Not open for further replies.
Top