Access to external memory

Discussions about CSEntry
Post Reply
Mariovaisman
Posts: 133
Joined: February 11th, 2013, 8:26 am

Access to external memory

Post by Mariovaisman »

Dear all,

I have written a new complex application, however I didn't find the way to access other areas of android device out of the csentry folder. I accessed external areas by file transfer using FTP or other transmission protocol, but I didn't see any way to do using for example the filecopy() function (from or to external areas of csentry).

The objective of this is to create a backup of the datafiles in an external memory or an external flash memory.

Thanks

Mario Vaisman
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Access to external memory

Post by josh »

On modern versions of Android (4.4 and above) there are security restrictions as to where applications are allowed to write files. You can access the many parts of the main storage (the same volume that contains the csentry directory) but on other volumes, such as external SD cards, apps can only can get to a special directory that has been created for them. You can find this directory by using the function pathname(CSEntryExternal). On my phone this directory is /storage/extSdCard/Android/data/gov.census.cspro.csentry/files. You should be able to write files to this directory using filecopy. Note that this is only supported in CSPro 6.2 and above (see this post http://www.csprousers.org/forum/viewtop ... 156&p=3277)
Mariovaisman
Posts: 133
Joined: February 11th, 2013, 8:26 am

Re: Access to external memory

Post by Mariovaisman »

Thnks Josh,
It is what I need, however, the situation is not exactly than this. I am using the OTG cable where I put an external flsh memory. I can see the content of that pendrive which is located in /storage/UsbDriveA if you see the android device. Using those standard tools that you can download from playStore like ES File Explorer, it is possible to create, read, write and delete from that device. However, I can not do anything from the CSPro application, Maybe CSEntry has no permissions to do it,

My point is to do a backup of the data to the external device and I pretend to use CSPro or to call to other app from CSPro to do it without any operator intervention other than to plug in the OTG cable with the flash memory (Pendrive), otherwise it is dangerous that anyone can see where are located the files and to do the backup and maybe delete those files.

Thanks

Mario Vaisman
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Access to external memory

Post by josh »

We don't have an OTG cable here so I can't be sure but I doubt that this will be possible from CSPro. Google is making access to external storage very difficult for applications for security reasons. Unless you are willing to root your device I don't think you will be able to get this to work.
Mariovaisman
Posts: 133
Joined: February 11th, 2013, 8:26 am

Re: Access to external memory

Post by Mariovaisman »

The OTG cable, permits to attach a pendrive to the tablet, as I see, CSPro has not permission to write in external pendrive device which is named as USBDRVA when the pendrive is attached. All interactive softwares as "ES File Explorer", or the original "My Files" can access to the pendrive. The problem with these softwares are that not only you can copy files from one side to the other, also you can delete files. I think CSPro cannot access the external pendrive because it has not defined those permissions to do it. This capability can be very useful to do backups in the field. In my case, I developed an application like DHS but in Android devices, and the supervisor tablets are servers for the enumerators, and need to have a backup in case something happens before the data is transmitted to the central office. This is a vulnerability that I want to close.

Would be interesting if you add this capability in the future releases.

Thanks

Mario
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Access to external memory

Post by josh »

CSPro already requests READ_EXTERNAL_STORAGE permission and WRITE_EXTERNAL_STORAGE permission. I can't find any other permissions in the Android documentation that we can request that would give us access to the pen drive. If you know what secret sauce ES File Explorer is using to be able to do this please let us know and we will add it to CSPro.
Sam Ralph
Posts: 2
Joined: October 11th, 2015, 5:49 am

Re: Access to external memory

Post by Sam Ralph »

Hi,
I am new on this platform. Could you please share an example of using filecopy to create backup on SD card from the menu
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Access to external memory

Post by josh »

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);
Sam Ralph
Posts: 2
Joined: October 11th, 2015, 5:49 am

Re: Access to external memory

Post by Sam Ralph »

Thanks so much Josh. I'll try this
Post Reply