Android Question Method to save/retrieve csv file

gezueb

Active Member
Licensed User
Longtime User
I have made a simple app to collect daily measurements of blood pressure and pulse. Data is stored in a file.DirInternal csv file. However, I would like to save and if necessary restore this data in/from a phone directory like downloads or documents, and this without any user interaction like content chooser etc. My phone (Galaxy Flip 3, Android 13) has no provision for external storage. Is there a simple way to save a backup file programmatically (in b4a) external to the app environment without the user choosing directory/filename like in Erel's text editor example? This for current Android versions 13+?
 

MicroDrie

Well-Known Member
Licensed User
I would like to save and if necessary restore this data in/from a phone directory like downloads or documents, and this without any user interaction like content chooser etc.
A perhaps very customer-friendly idea in itself, but it is contrary to the current Android OS security rules of Android. They require that this does not happen without the user's consent and without the user's knowledge.

Perhaps you can bypass these security rules by adding an FTP server/client with a download script to your app.
 
Upvote 0

gezueb

Active Member
Licensed User
Longtime User
Thank you, MicroDrie, I would not mind permissions to be asked (that's once only at install time ) and I do not care to publish something on Google Play. But I hate the idea that the user has to pick directory and file name just for a simple backup/restore. FTP is certainly an option, email and whatsapp can also be used to send and receive csv data, however they all require user interaction. At present I use Erel's Texteditor to save/restore data that is copied to/from my app via Clipboard.
 
Upvote 0

jimich

Member
Licensed User
Longtime User
If you want to save csv file in directory like downloads or documents, you have to lower your targetSdkVersion to 28 or lower. (of course, you can't publish it). I always did this if I want to easy transfer or retrieve csv files.
 
Upvote 0

MicroDrie

Well-Known Member
Licensed User
The great thing about asking yourself what are the "purpose and means" is that it provides an explanation for a solution. When you talk about download and document directories, I see the purpose as (re)using the information received by (an app from or) the user himself. In that case, you could choose to build in an export function where the user can decide where to put it. That seems acceptable for a single occasion and is in line with the increasingly strict access rules to directories. On the other hand, if your solution contains everything that is useful to the user, why does he need a publicly accessible access point?
 
Upvote 0

gezueb

Active Member
Licensed User
Longtime User
Sorry MicroDrie, I do not quite agree. While most PC and Mac users have at least a faint idea about the directory structure of their computer(s) and where they should put files like documents etc, this is certainly not the case with most smart phone and tablet users. Apart from a few developers and freaks, no normal samrt phone user has a clue where Android or IOS stores its bits. The OS's do not advertise their data and program structure and omit on purpose something like a file explorer that could provide insight.
Thus, it is asked too much of a normal user to select the directory where backups should be stored. I just picked download and document directories as examples, because they sound at least familiar to a Windows user. Therefore, it is up to the developer to define where to store necessary files for backup or transfer and not to the user, because he/she just simply does not know or care about the internals of his phone. But sadly, Android does not allow this anymore.
Anyway, thank you for your input and have a nice weekend, Georg
 
Upvote 0

gezueb

Active Member
Licensed User
Longtime User
FYI: I am using now a stripped down version of AGrahams "Manage External Storage" example without the directory/file-selection dialoge to copy files from internal storage to external and back.
https://www.b4x.com/android/forum/t...cess-internal-external-storage-sdk-30.130411/
Thus, external directory and filename are coded (DCIM/backup) and not required to be selected by the user. I choose the DCIM directory because one can explore this directory via USB which makes debugging easier. Obviously, Google would not permit these permissions in the Play Store, but I couldn't care less. To retrieve the file in the case the backup is needed, the file.copy goes the other way. No user input required at all.
As noted, the manifest must contain the permission request:
B4X:
AddPermission(android.permission.MANAGE_EXTERNAL_STORAGE)
SetApplicationAttribute(android:requestLegacyExternalStorage, true)
 
Last edited:
Upvote 0
Top