not able to copy file to sd card

Discussions about CSEntry
Jing Liu
Posts: 42
Joined: July 1st, 2015, 3:19 am

not able to copy file to sd card

Post by Jing Liu »

Hi,

I have CS entry installed on the main storage of my mobile and i would like to copy some data files to the sd card.

If i use fileexist(), then i can find files on sd card, but i cannot copy files to that folder, neither generate new files or delete files there.


best

Jing

DirBackup = "/storage/extSdCard/Data";
DirData = PathName( CSpro );

function related:

function BackupF()
{Eliminates files not rquired }
FileDelete( concat( strip(DirData), "?", strip(xDataFNum), ".DAT.log" ));
if FileExist( concat( strip(DirBackup), "/CONNECT.TXT" )) = 0 then
errmsg( "connecting file not found" );
else
{Added extra protection - if data file reduces in size, generate a copy file of the prior backup}
do i = 1 while i <= 2 // i is the same to digits of DataFcodes !!
BackupOldF(i);
enddo;
numeric test1 = FileCopy( concat( strip(DirData),"?",strip(xDataFNum), ".*" ), strip(DirBackup) );
endif;
end;

best

Jing
josh
Posts: 2403
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: not able to copy file to sd card

Post by josh »

It could be file permission issue. In more recent versions of Android they have been restricting the directories that programs are allowed to write into. However before I blame it on Android I would make sure that there isn't something wrong with the file paths you are giving to filecopy. Maybe print them out with an errmsg and double check them just to make sure. It is really easy to miss a "/" somewhere. Also I would try the copy without using the wildard (no ? or *) and make sure it works in that simple case.
Jing Liu
Posts: 42
Joined: July 1st, 2015, 3:19 am

Re: not able to copy file to sd card

Post by Jing Liu »

Hi,

I don't think it was caused by an path error, because I can find the file with fileexist() and get the file size with filesize(), but i cannot copy or delete them.

best

Jing
Jing Liu
Posts: 42
Joined: July 1st, 2015, 3:19 am

Re: not able to copy file to sd card

Post by Jing Liu »

Hi,

I am not sure if this is also related to permission problem.

I can sync files from the csentry folder to another csentry folder through blue tooth, but i cannot do that from a sub folder or to a subfolder.

those two lines do not work, i don't get any error message, it says the transfer is successful, but the files never should up in the target folder.

Do you have any suggestion for this? Having hundreds of files together with other entry files is kind of annoying.

ClientPath=/Data

ServerPath=/TempData

best

Jing
josh
Posts: 2403
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: not able to copy file to sd card

Post by josh »

I will test using filecopy to write to the sdcard on my phone and I see if I can reproduce your problem.

You should definitely be able to copy between subfolders using Bluetooth. I have done it before. You may want to look at the file synclog.txt that gets generated in the csentry folder on the tablet/phone that you are using as the client. It lists all the sync commands that are run, the file transfers that happen as well as any errors. If you are using put commands and the file is not found on the client there is no error shown so it could say that the sync was successfull even if the files to put were not found. It is done this way since you often have the commands to get the application files and put the data files in a single sync spec file and the first time you run it the data files don't exist.
josh
Posts: 2403
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: not able to copy file to sd card

Post by josh »

I am able to reproduce the problem with copying to the external SD card on my phone. I can use fileexist and dirlist on the external SD card but dircreate and filecopy are failing. From what I see on the web it is linked to Android security measures introduced in Android 4.4. They don't want any application to be able to write anywhere on the SD card. I don't see any easy workarounds at this point but I will look into it some more.
Jing Liu
Posts: 42
Joined: July 1st, 2015, 3:19 am

Re: not able to copy file to sd card

Post by Jing Liu »

Hi Josh,

Thanks a lot for the effort you put on this.

I did a bit more testing, about transfer files into a subfolder through blue tooth. As far as I can see, 'serverpath' does not function as expected. I can only copy files into subfolder when the subfolder is defined as the root folder on server. If it is not done that way, then bluetooth will not recognize 'serverpath' but copy all the files to the csentry root folder.

best

Jing
josh
Posts: 2403
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: not able to copy file to sd card

Post by josh »

Jing,

Please send me the .pnc files you are using on client and server plus the synclog.txt file from the client so I can try to reproduce the problem.

Josh
Jing Liu
Posts: 42
Joined: July 1st, 2015, 3:19 am

Re: not able to copy file to sd card

Post by Jing Liu »

Hi Josh,

I am sorry for replying late. I was traveling and then struggling with some internet problem.

The currect pnc file works and I can send data files to the subfolder /TempData.

But if I remove /TempData/ from the server pnc file and add serverpath = /TempData/ into the client pnc file, then it will not recognize that.

best

Jing
You do not have the required permissions to view the files attached to this post.
josh
Posts: 2403
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: not able to copy file to sd card

Post by josh »

For copying to the external SD card this is an issue with the new security model in Android 4.4 and above. As of Android 4.4 applications are only allowed to write files to a special directory on the SD card. For CSPro this will be /storage/extSdCard/Android/data/gov.census.cspro.csentry/files. Unfortunately to create this directory the application has to execute some initialization code that is not done in CSPro 6.1. We have added this code in CSPro 6.2 beta which should be available shortly. In that version you should be able to use filecopy to copy to the external SD card but you will have to put your files into /storage/extSdCard/Android/data/gov.census.cspro.csentry/files.
Post Reply