PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV Mobile 2024 → Best practice for storing a file on Android
Best practice for storing a file on Android
Débuté par Jim, 11 mar. 2019 15:11 - 8 réponses
Posté le 11 mars 2019 - 15:11
I am almost finished with an app that can grab temperature data from a hardware unit of ours and store it as a .csv file.
The customer will likely need to get at it to email it to someone or themselves for long term storage.

What location would be easiest for the end user to get at?
I used this for the emulator. file_path is string = fCurrentDir
If I used this for the app, it wasn't browsable.

I used this for the app on the phone. file_path is string = /storage/emulated/0/android/data/com.mycompany.appname/files"
This was kind of hard to browse to, so I don't expect a customer to be able to get to it easily.

Should I drop it in their downloads?
What is the best practice?

Thanks

Jim
Membre enregistré
498 messages
Popularité : +8 (8 votes)
Posté le 11 mars 2019 - 16:01
Hi Jim

Well You could let your file on downloads.

For me it's more like create the own file app and let it be on the storage of the device.
You could let it be on the device storage or on a SD card the choice it's yours.

Hope this could help you.

--
Best Regards
ARV
Posté le 12 mars 2019 - 14:27
Thanks.

I tried downloads, that didn't work.
My default path now, /storage/emulated/0/android/data/com.mycompany.appname/files, did not work on two other devices, one phone one tablet. The path simply wasn't there. I was looking at this location as it seems like the equivalent to the Program Files (X86) folder on Windows. Apparently it isn't. In fact on the other two devices I could not even find where the app installed.

Any good tutorials out there explaining the Android file system?
Membre enregistré
498 messages
Popularité : +8 (8 votes)
Posté le 12 mars 2019 - 15:12
Hi Jim

Maybe the examples of windev about file searching.

Now about what you write it's seems that you think this path:
/storage/emulated/0/android/data/com.mycompany.appname/files

You think that this is iqual to another devices, wich it isn't true, all the path change.

Use more like the functions of windev like:
SysDirStorageCard()
This will give you the root of the device more like C:/ on PC

I let you the source:
https://help.windev.com/en-US/…

search on help for the Sysxxxx functions.

also fCurrentDir it's more like where the app is install it I think not sure about that.
another thing to take it's that you could use fDataDir but this is more where are the HFSQL Classic are installed (You won't use this but in the future could help you)


now about what you want to do you could do something like this:
-Use the SysDirStorageCard or use SysDirExternalStorage (search for this on the help page on PCSoft for more info)
-with this path create your own file of your app like fMakeDir(SysDirStorageCard+fsep()+"nameofyourapp")
-save that path between the () and that's your file of your app on the "C:/" for Android.

Take in mind that all of the "C:/" files change a lot on every device, like
Samsung could have the path:
/storage/emulated/0/
but Huawei could have for said something:
/storage/0/

so that's why you see that the file doesn't exist.

Hope this info could help you.
Good luck my fellow developer.

--
Best Regards
ARV
Message modifié, 12 mars 2019 - 15:12
Posté le 12 mars 2019 - 17:05
ARV,

Thanks.
I have been studying this all morning and building a test app.
It looks like I will be using fCurrentDir from now on.

Thanks again. It is appreciated.

Jim
Membre enregistré
498 messages
Popularité : +8 (8 votes)
Posté le 12 mars 2019 - 18:07
Hi Jim

Glad to read that

You know, theres one more thing about your decision
This is what PCSoft Help web page said about the result of that function "fCurrentDir":
This directory corresponds to the directory that will be used to store the private application files in the internal storage area ("files" directory). You have the ability to read and write in this directory.


it's look like the app you build it's the only one can see this file, no other app could access to that path so becareful.
Hope all of this info could help
Good Luck!

Source:
https://help.windev.com/en-US/…

--
Best Regards
ARV
Posté le 12 mars 2019 - 18:17
ARV,

Thanks again. I just found that out while trying to attach the file to email it.
I will explore SysDirStorageCard() some.

Jim
Posté le 12 mars 2019 - 19:03
ARV,

Looks like SysDirStorageCard() is the ticket. You're the Genius my friend.
It works.
I kept thinking this was directed towards the SD Card.
It is really internal storage.

Jim
Membre enregistré
498 messages
Popularité : +8 (8 votes)
Posté le 13 mars 2019 - 14:17
Hi Jim

Nice! you solve your problem

Jim wrote:
ARV,

Looks like SysDirStorageCard() is the ticket. You're the Genius my friend.
It works.
I kept thinking this was directed towards the SD Card.
It is really internal storage.

Jim


Yes
SysDirStorageCard()


With this is the internal storage of the device so don't worry

if you want to save something on the SD card it's with this:
SysStatusExternalStorage()

but this function have two parameters the slot of the SDCard and what type do you want to save.
Another thing to take it's that PCSoft tell you to know the state of the SDCard so becareful

This is the function to know about the status:
SysStatusExternalStorage()


To know about the slot or Subscript or number of the SDCard it's with this:
SysNbExternalStorage()


IMPORTANT:
But all of this about the SDCard ONLY WORKS on Windev Mobile 21 and beyond

Sources:
SysDirExternalStorage:
https://help.windev.com/en-US/…

SysStatusExternalStorage:
https://help.windev.com/en-US/…

SysNbExternalStorage:
https://help.windev.com/en-US/…

--
Best Regards
ARV
Message modifié, 13 mars 2019 - 14:20