How save data on external storage Android

Discussions about CSEntry
Forum rules
New release: CSPro 8.0
Post Reply
diaznhugo
Posts: 18
Joined: December 1st, 2016, 7:24 am

How save data on external storage Android

Post by diaznhugo »

Hey guys i want know how to save data to external storage on Android like external usb memory.

Is for backup purpose

Thanks
Hugo Diaz Nuñez
Dominican Republic
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: How save data on external storage Android

Post by josh »

The security restrictions in Android mean that an application is only allowed to write to one special per application folder on an external SD card. This folder varies from device to device. To get the folder path for your device use the pathname function with CSEntryExternal. On my tablet the folder is /storage/extSdCard/Android/data/gov.census.cspro.csentry/files but this may be different on your device. We have also seen some devices where even though there is an external SD card the device does not support copying to it from apps other than the built in file explorer.

Here is a code snippet that copies the file data.csdb from the application folder to a folder named backup concatenated with the current time on the external SD card:
string backupFolder = pathname(CSEntryExternal) + maketext("Backup%d",timestamp());
dircreate(backupFolder);
filecopy(pathname(Application) + "data.csdb",backupFolder);
diaznhugo
Posts: 18
Joined: December 1st, 2016, 7:24 am

Re: How save data on external storage Android

Post by diaznhugo »

Thanks Josh.
Hugo Diaz Nuñez
Dominican Republic
Yana
Posts: 51
Joined: October 6th, 2016, 6:57 am

Re: How save data on external storage Android

Post by Yana »

Dear teams
How to fix this problem while trying to copy to Android sd card. But I wrote the logics correcrly.
Attachments
Errors message while trying to copying
Errors message while trying to copying
Screenshot_2017-11-23-10-56-34.jpg (205.47 KiB) Viewed 6290 times
pollyp20
Posts: 4
Joined: June 21st, 2020, 9:08 am

Re: How save data on external storage Android

Post by pollyp20 »

Sir how about in making backup on internal storage, incase there is no sdcard installed..what is the logic to be used?
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: How save data on external storage Android

Post by josh »

You can just filecopy() as above but instead of pathname(CSEntryExternal) use pathname(CSEntry) to get the path to the CSEntry directory on the device storage.
pollyp20
Posts: 4
Joined: June 21st, 2020, 9:08 am

Re: How save data on external storage Android

Post by pollyp20 »

Sir i tried sa pathname (CSEntry) its says backup complete.but i only creates the folder, no data files copied..
Here is my folder structure
CrPS (main folder)
Program (sub folder)
Menu (sub folder,where the command backup data files is here)
Data(sub folder,where data files located)
CrPS\Program
CrPS\Menu
CrPS\Data
akosipaul20
Posts: 1
Joined: April 29th, 2020, 1:55 am

Re: How save data on external storage Android

Post by akosipaul20 »

pollyp20 wrote: June 22nd, 2020, 7:14 pm Sir i tried sa pathname (CSEntry) its says backup complete.but i only creates the folder, no data files copied..
Here is my folder structure
CrPS (main folder)
Program (sub folder)
Menu (sub folder,where the command backup data files is here)
Data(sub folder,where data files located)
CrPS\Program
CrPS\Menu
CrPS\Data
Attachments
Capture.JPG
Capture.JPG (61.82 KiB) Viewed 4159 times
khurshid.arshad
Posts: 571
Joined: July 9th, 2012, 11:32 am
Location: Islamabad, Pakistan

Re: How save data on external storage Android

Post by khurshid.arshad »

I am also using compress function for backup to save space.

Code: Select all

compress (concat(SDPathdatetime, ".zip"), csdbfiles);
best.
a.
Post Reply