Strange - Retrieve image from folder

The place to discuss anything and everything about running your LiveCode on Android

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
gnor
Posts: 53
Joined: Fri May 08, 2020 10:32 pm

Strange - Retrieve image from folder

Post by gnor » Sat Jul 02, 2022 9:26 am

Hello everyone!

I heve created an android app that saves images as jpeg with my given filenames into the folder /store/emulated/0/Documents/akpictures of the device.
Then i retrieve the filenames and place them into datagrid, then clicking on a row in the grid, sets the filename of image placed onto the card to the filename. Working well.
Starting the application, taking pictures, saving them and filling the datagrid goes well. After a while, my previously taken pictures file names does not show in the retrieved filelist from the folder above. Everything is still there, but filenames are missing...
As far i see, nothing changes in their filenames. Is there any metedata or something that cause this?
Seems like showing only the last few taken pictures somehow...
I've also tried to copy into the folder, rename it but that also missing when listing files of that folder.

Here is my code snippet:

put "" into gFileList
put "/storage/emulated/0/Documents/AKPICTURES" into tFolder
set the defaultfolder to tFolder
put the files into tFileList
ANSWER tFileList ------------------------here i dont see all my files but why????

put tFileList into temp
repeat for each line L in temp
put L & cr after gFileList -- add to global
end repeat

--datagrid filling etc.
Anyone has some hints what causes this ?
Could it be than android has some of locking permissions or anything else?

Thank you!

stam
Posts: 2634
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Strange - Retrieve image from folder

Post by stam » Sat Jul 02, 2022 11:58 am

your code does work although can be refactored.

I think your error is in the file path you provide:

Code: Select all

put "/storage/emulated/0/Documents/AKPICTURES" into tFolder
if this is relative to the stack, then it should be

Code: Select all

specialFolderPath("resources") & "/storage/emulated/0/Documents/AKPICTURES"
but in any case you need to provide either a FULL file path, or something that uses a specialFolderPath to get the full file path...

Specifially i used your code in a button - i substituted your file path with one that you pick with an answer dialog (since i don't want clutter my system) and it works just fine:

Code: Select all

global gFileList

on mouseUp
   local tFolder, tFileList
   put "" into gFileList
   answer folder "select a folder with files of interest"
   if it is empty then exit mouseUp
   put it into tFolder
   set the defaultfolder to tFolder
   put the files into tFileList
   ANSWER tFileList ------------------------WORKS
   repeat for each line L in tFileList
      put L & cr after gFileList -- add to global 
   end repeat
end mouseUp
note that 'temp' isn't needed and has been removed.
Only you know if you actually need a global variable, it's often better to use a script local variable...

hope that helps,
Stam

gnor
Posts: 53
Joined: Fri May 08, 2020 10:32 pm

Re: Strange - Retrieve image from folder

Post by gnor » Sat Jul 02, 2022 2:09 pm

Thanks Sam

I see you selecting the folder thru answer dialog.
I think that is not needed in my code, since i want the user to hit a button and see the list of files in datagrid.
I m able to take picture and save it into that folder. My code returns the list of files, and let us say i close the app and reopen it after a while, i m not able to get all the files was prewiously taken into the list. So that is why i'm thinking of something else. If i m using the app, returns all file i have taken when the app is running. I close the app,
And i never see the previously taken pictures in the list. But if i take another pictute, the actual picture shows up in the list.
So if you have an idea, would be happy to hear it.
Thanks again of your time

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7215
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Strange - Retrieve image from folder

Post by jacque » Sat Jul 02, 2022 5:05 pm

Android disallows access to the public folders, apps can only access the documents folder inside the app sandbox. I've submitted a feature request for access to the public documents folder but for now you can only work with the items in the app's sandbox.

Change the file path to specialfolderpath("documents") and it should work. You don't need any subfolders in there if images are all you're storing.

BTW, answer files doesn't work on mobile.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

stam
Posts: 2634
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Strange - Retrieve image from folder

Post by stam » Sat Jul 02, 2022 5:33 pm

sorry i missed the bit that this was a mobile app (i just check for unread items and don't necessarily pay attention to the subform... doh!), but to some extent the point stands.
gnor wrote:
Sat Jul 02, 2022 2:09 pm
Thanks Sam

I see you selecting the folder thru answer dialog.
I think that is not needed in my code, since i want the user to hit a button and see the list of files in datagrid.
I m able to take picture and save it into that folder. My code returns the list of files, and let us say i close the app and reopen it after a while, i m not able to get all the files was prewiously taken into the list. So that is why i'm thinking of something else. If i m using the app, returns all file i have taken when the app is running. I close the app,
And i never see the previously taken pictures in the list. But if i take another pictute, the actual picture shows up in the list.
So if you have an idea, would be happy to hear it.
Thanks again of your time
I used the answer folder example to highlight that it was an issue with your file path, not your code.

As Jacque says you won't have access to non-app related storage on mobile as everything is sandboxed.
Perhaps at the time of photo capture if possible store a copy of the file in your app folder? (ie specialFolderPath("resources")) - that way you will be able to access no problem.
But in truth i don't know enough about mobile/android to advise further - perhaps there is an OS level API that will let you access?

S.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7215
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Strange - Retrieve image from folder

Post by jacque » Sat Jul 02, 2022 6:31 pm

stam wrote:
Sat Jul 02, 2022 5:33 pm
sorry i missed the bit that this was a mobile app (i just check for unread items and don't necessarily pay attention to the subform... doh!), but to some extent the point stands.
I do that all the time. Then I get embarrassed.

For mobile apps, the resources folder is synonymous with the engine folder and is read only. Permanent storage is pretty much limited to the documents folder. You can access the temporary folder but it could be wiped if the OS needs room.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

SparkOut
Posts: 2839
Joined: Sun Sep 23, 2007 4:58 pm

Re: Strange - Retrieve image from folder

Post by SparkOut » Sat Jul 02, 2022 6:48 pm

jacque wrote:
Sat Jul 02, 2022 5:05 pm
Android disallows access to the public folders, apps can only access the documents folder inside the app sandbox.
I always think "disallowed public folders" is an oxymoron. Folder management is the biggest bugbear I have with Android.

gnor
Posts: 53
Joined: Fri May 08, 2020 10:32 pm

Re: Strange - Retrieve image from folder

Post by gnor » Sun Jul 03, 2022 3:43 pm

Thank You guys!

Only one more thing you might know the answer to.
How can i save the mobilepickphoto camera taken picture from my android phone to my pc filesystem if it is at remote location.
Also later want to see them in my app.
I have a static ddns.net adress on my network forwarded to my pc, using it with my database.
I do save pictures into my database already, but to retrieve them is slow, even if they are small. So i need this solution to have my pictures in the filesystem in bigger size and resolution. Actually i need both case for different pourpouses. I have read a lot about it, but never succeed to accomplish.
Using livecode 9.6.3 community version, so also confused what can and can not be done.

Thanks

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7215
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Strange - Retrieve image from folder

Post by jacque » Mon Jul 04, 2022 6:30 pm

mobileComposeMail will show the standard Share dialog. Users can then choose the location to place the file. The command isn't only for email, it seems to work for anything. One option would be to share to Google Drive but I'm not sure if that would be faster.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

gnor
Posts: 53
Joined: Fri May 08, 2020 10:32 pm

Re: Strange - Retrieve image from folder

Post by gnor » Tue Jul 05, 2022 5:51 pm

Thanks
I will check on that.
Sorry for the late answer.

Post Reply

Return to “Android Deployment”