Custom gallery viewer

Hi,

Is it possible to do our own image gallery viewer without creating custom enterprise code ?

For example, would it be possible to use the LFS api to browse the image gallery folder of the mobile device ?

If this is not possible, does Corona plan to give us access to the image folder, so we could browse it and build our own media browser.

thanks

Nick

There are a few ways to create an “image gallery viewer”, so I’m not exactly sure the functionality you’re trying to achieve. However, there is the selectPhoto() API which lets you access the device’s saved images:

https://docs.coronalabs.com/api/library/media/selectPhoto.html

Yes, I know about the selectPhoto API, but its not what we need. We want to create our own gallery viewer so its embedded with our app. So for us, the ability to access the directory, iterate image files and drawn them on our side (with our code) is what we are looking for.

Ah, I apologize for the misunderstanding. 

This might work on Android, but it’s less likely to work on iOS. Apple wants you to use system dialogs to access these folders. Its part of how they secure the device. On Android I believe any app has at least read access to the photo folder.  The problem is it seems to vary from Android version to version.

yes it’s possible, and it will work on both android and IOS, i’ve done it in a project while ago. don’t remember how i did it but i think i went to LFS route as you sugested. i had a  mini file manager that shows the images in a list, i could tap them to show the image. you could even delete them or insert more from camera or from the phone gallery.

Wow! Didn’t think that is possible. I have to try it. Can you share any LFS knowledge on this? Where to navigate etc.

i’ve manage to find the project.

the base of the project was to get the list of files in a directory, from there is pretty easy. just put the result on a tableview, inside the tableview you can add the preview images or delete images or insert more images.

the code to get the content i used (hope this will help you):

workingDrectory should be system.TemporaryDirectory or any other valid base.

tempDir should be the name of a folder you want to get the content. if you want to add and remove content you can’t work on system.ResourceDirectory you need to transfer first the content from there to  system.TemporaryDirectory or system.DocumentsDirectory.

local function getContentDir(tempDir,workingDirectory) local lfs = require "lfs" local dname = tempDir or nil local workingDir = workingDirectory or nil local tabelaRetorno={} local contador=1 if dname and workingDir then local docs\_path = system.pathForFile( "", workingDir ) local success = lfs.chdir( docs\_path ) -- returns true on success if success then if (lfs.attributes(dname, "mode") == "directory") then local existe = system.pathForFile( dname, workingDir ) if existe then for file in lfs.dir(existe) do local resultOK, errorMsg if (lfs.attributes(file, "mode") ~= "directory") then tabelaRetorno[contador]=file contador=contador+1 end end end else print ("pasta nao existe. nao tem nada para apagar!") end else print ("problema a aceder a pasta") end end return tabelaRetorno end

to learn lfs:

https://coronalabs.com/blog/2012/05/08/luafilesystem-lfs-tutorial/

https://coronalabs.com/blog/2013/02/13/faq-wednesday-sub-folder-and-file-access/

Thanks, but I thought you were talking about creating a custom image picker for the built in photos/camera roll in iOS.

The other stuff I already know about.

The images from the image gallery should be located here on iOS: /private/var/mobile/Media/DCIM/

I just tried changing the directory with LFS into that directory and I get an error on device saying ‘the operation is not permitted’, so I am pretty sure it isn’t possible… because apple doesn’t allow it.

sorry. i didn’t understood your question right. i thought you wanted your own image gallery viewer. not to substitute the native image gallery in the device. as far as i know, it’s not possible to have access to that without enterprise.

There are a few ways to create an “image gallery viewer”, so I’m not exactly sure the functionality you’re trying to achieve. However, there is the selectPhoto() API which lets you access the device’s saved images:

https://docs.coronalabs.com/api/library/media/selectPhoto.html

Yes, I know about the selectPhoto API, but its not what we need. We want to create our own gallery viewer so its embedded with our app. So for us, the ability to access the directory, iterate image files and drawn them on our side (with our code) is what we are looking for.

Ah, I apologize for the misunderstanding. 

This might work on Android, but it’s less likely to work on iOS. Apple wants you to use system dialogs to access these folders. Its part of how they secure the device. On Android I believe any app has at least read access to the photo folder.  The problem is it seems to vary from Android version to version.

yes it’s possible, and it will work on both android and IOS, i’ve done it in a project while ago. don’t remember how i did it but i think i went to LFS route as you sugested. i had a  mini file manager that shows the images in a list, i could tap them to show the image. you could even delete them or insert more from camera or from the phone gallery.

Wow! Didn’t think that is possible. I have to try it. Can you share any LFS knowledge on this? Where to navigate etc.

i’ve manage to find the project.

the base of the project was to get the list of files in a directory, from there is pretty easy. just put the result on a tableview, inside the tableview you can add the preview images or delete images or insert more images.

the code to get the content i used (hope this will help you):

workingDrectory should be system.TemporaryDirectory or any other valid base.

tempDir should be the name of a folder you want to get the content. if you want to add and remove content you can’t work on system.ResourceDirectory you need to transfer first the content from there to  system.TemporaryDirectory or system.DocumentsDirectory.

local function getContentDir(tempDir,workingDirectory) local lfs = require "lfs" local dname = tempDir or nil local workingDir = workingDirectory or nil local tabelaRetorno={} local contador=1 if dname and workingDir then local docs\_path = system.pathForFile( "", workingDir ) local success = lfs.chdir( docs\_path ) -- returns true on success if success then if (lfs.attributes(dname, "mode") == "directory") then local existe = system.pathForFile( dname, workingDir ) if existe then for file in lfs.dir(existe) do local resultOK, errorMsg if (lfs.attributes(file, "mode") ~= "directory") then tabelaRetorno[contador]=file contador=contador+1 end end end else print ("pasta nao existe. nao tem nada para apagar!") end else print ("problema a aceder a pasta") end end return tabelaRetorno end

to learn lfs:

https://coronalabs.com/blog/2012/05/08/luafilesystem-lfs-tutorial/

https://coronalabs.com/blog/2013/02/13/faq-wednesday-sub-folder-and-file-access/