accessing a path outside csentry in the memory card

Discussions about creating CAPI applications to run on Android devices
Forum rules
New release: CSPro 8.0
Post Reply
AriSilva
Posts: 591
Joined: July 22nd, 2016, 3:55 pm

accessing a path outside csentry in the memory card

Post by AriSilva »

I´m trying to have access to this path:
Card/Android/data/science.foto/files/csentry/u
The path exists in the card, and it has some contents (some files that I want to syncfile to the server).
I´ve tried a path concat like

x = pathname(CSEntryExternal);
y = "..\..\science.foto\files\csentry\u";
dirSource = pathconcat(x,y);

I displayed dirSource and it seemed well
/storage/extSdCard/Android/data/science.foto/files/csentry/u
but when I executed a dirlist on that directory the list.length() came as 0, meaning that there wre no files there.
What am I doing wrong?
Is there another way to get those files outside csentry?
Best
Ari
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: accessing a path outside csentry in the memory card

Post by josh »

For security reasons Android won't let you access the private files of another app. Anything under Android/data/... is considered app private data so CSEntry can only access files under Android/data/gov.census.cspro.csentry. It can't access files under Android/data/someotherapp. Depending on the version of Android you are using you might be able to put the files outside of the Android/data directory such as /mnt/sdcard/, /mnt/sdcard/Pictures or /mnt/sdcard/Downloads. Google has been making it progressively more difficult to work with files in each new version of Android. I'm pretty sure that would work in versions 9.0 and earlier and pretty sure it will not work in Android 11. In Android 11 apps are not allowed to directly read or write files outside of their app private directories which is why in CSPro 7.5 we moved the CSEntry directory from /mnt/sdcard/csentry to Android/data/gov.census.cspro.csentry for new installs (on devices that had CSPro 7.4 and earlier access to the old csentry is grandfathered in). It is unfortunate that Google has added all of these file restrictions as it makes it very difficult for apps like CSEntry that do a lot of operations on files.

What kind of file are you trying to access in the science.foto directory? Are they generated by an app that you wrote (and could modify) or is something that you cannot change? I ask because maybe we can figure out another way to share the data.
AriSilva
Posts: 591
Joined: July 22nd, 2016, 3:55 pm

Re: accessing a path outside csentry in the memory card

Post by AriSilva »

Thanks, Josh, for the prompt (as always) answer.
My Android version is 5.1.1, and it has not this mnt directory.
In any case, I do not want to depend on something from Google that might not be working tomorrow.
The application I´m calling is an in-house (written by a colleague of mine) to take photos of "vaccine booklets" of the children being interviewed.
These booklets have information about the vaccine type anda date for the children.
These photos (more than one per child) are .jpg files stored in the card (using that science.foto path that I wrote before)
Then, we would transfer those photos to the server by the menu-control program, and that is the point when I need to hace access to the card directory outside csentry.
Is there a way that these two applications (science.foto and csentry) could share a common directory?
By the way, my knowledge of Android is very limited.
Best
Ari
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: accessing a path outside csentry in the memory card

Post by josh »

On Android 5.1 you should be able to create a directory in the top level fo the sd card. The full path on the device would be /mnt/sdcard on most devices but when you look at it from Windows by connecting to the device by USB it won't show the /mnt/sdcard part.

Android has some other mechanisms for sharing files between apps described here: https://developer.android.com/training/ ... le-sharing Unfortunately I'm not sure those mechanisms would work in CSPro without some modification of CSPro itself. If you were sharing text data you could use the systemapp object to send it from the foot app back to csentry through an Intent but I don't think that would work with photos since it is binary data and we don't have a way to handle that kind of data in CSPro. This is something that would be useful to be able to handle so we will consider implementing some kind of file sharing solution for CSEntry in the future but for now I don't have a good solution.
AriSilva
Posts: 591
Joined: July 22nd, 2016, 3:55 pm

Re: accessing a path outside csentry in the memory card

Post by AriSilva »

Suppose I can write the photo files with my app on this /mnt/card directory.
How do I access it from csentry in order to syncdata them to the server?
Best
Ari
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: accessing a path outside csentry in the memory card

Post by josh »

You can just do syncfile("/mnt/sdcard/fotos/" + my filename, ...)
Post Reply