android - save the new camera picture

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Volkmar
Posts: 16
Joined: Thu Mar 22, 2018 6:24 pm

android - save the new camera picture

Post by Volkmar » Sun Apr 29, 2018 2:46 pm

I try to make a picture with the android camera and will save it immediately.

The code below doesn't function. Please, can you help me.

Code: Select all

on mouseUp
   mobilePickPhoto "camera"
   put the result into URL("binfile:"&specialFolderPath("documents")&"/pic.jpg")
end mouseUp
Thanks a lot
Volkmar

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: android - save the new camera picture

Post by bogs » Sun Apr 29, 2018 2:57 pm

I don't dev for mobile, but what happens if, instead of binfile, you just use file?

Code: Select all

put the result into URL("file:"&specialFolderPath("documents")&"/pic.jpg")
Image

Volkmar
Posts: 16
Joined: Thu Mar 22, 2018 6:24 pm

Re: android - save the new camera picture

Post by Volkmar » Sun Apr 29, 2018 3:11 pm

Thanks for the quick response.

I try the code below, but I doesn't found the picture at the android storage.

At the file manager I found a the folder "Documents" with capital letter at the beginning. Is that the storage folder?

Code: Select all

on mouseUp
   mobilePickPhoto "camera"
   put the result into URL("file:"&specialFolderPath("documents")&"/pic.jpg")
end mouseUp
Do you have an other idea?

bogs
Posts: 5435
Joined: Sat Feb 25, 2017 10:45 pm

Re: android - save the new camera picture

Post by bogs » Sun Apr 29, 2018 3:23 pm

Well, you could try changing 'documents' to 'Documents' in the path, although the dictionary doesn't list it that way. Beyond that, I just don't know enough about the environment your developing for. Hopefully someone that does can chip in.
Image

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: android - save the new camera picture

Post by Klaus » Sun Apr 29, 2018 3:44 pm

Hi Volkmar,

from the dictionary about "mobilepickphoto":
...
If the user cancels the pick, the command returns with result cancel.
Otherwise a new image object is created on the current card of the
default stack containing the chosen image.
...

Means your script does not work, do something like this:

Code: Select all

on mouseUp
   mobilePickPhoto "camera"
   ## User clicked CANCEL:
   if the result = "cancel" then
       exit mouseup
   end if
   put last img into URL("binfile:"& specialFolderPath("documents") & "/pic.jpg")
   
   ## Optional:
   delete last img
end mouseUp
spcecialfolderpath("documents") (yes, a small d is correct, since iOS and Android are case-sensitive OPs!) is the folder on mobile where we definitively have write permission, so everything we/the user will save to disk goes here!

Best

Klaus

Volkmar
Posts: 16
Joined: Thu Mar 22, 2018 6:24 pm

Re: android - save the new camera picture

Post by Volkmar » Sun Apr 29, 2018 3:57 pm

Sorry, but the code doesn't save the picture.

Must I note other thinks/permissions or must I create the folder specialFolderPath("documents") ?

Code: Select all

on mouseUp
   mobilePickPhoto "camera"
   ## User clicked CANCEL:
   if the result = "cancel" then
      exit mouseup
   end if
   put last img into URL("binfile:"& specialFolderPath("documents") & "/pic.jpg")
   
   ## Optional:
   --delete last img
end mouseUp

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: android - save the new camera picture

Post by Klaus » Sun Apr 29, 2018 4:05 pm

Hi Volkmar,

no, the folder is already there, no need to create it. Try this:

Code: Select all

on mouseUp
   mobilePickPhoto "camera"
   ## User clicked CANCEL:
   if the result = "cancel" then
      exit mouseup
   end if

   ## We try to export the image to a JPG file:
   export last img to file (specialFolderPath("documents") & "/pic.jpg") as JPEG

   ## If the export fails for some reason, maybe we get some hint from THE RESULT
   if the result <> EMPTY then
      answer "Error while exporting image:" && the result
  end if
   ## Optional:
   --delete last img
end mouseUp
Best

Klaus

Volkmar
Posts: 16
Joined: Thu Mar 22, 2018 6:24 pm

Re: android - save the new camera picture

Post by Volkmar » Sun Apr 29, 2018 5:18 pm

There is no error message.
The photo will be created, but the picture wouldn't saved.

Do you have any ideas?

Code: Select all

on mouseUp
   mobilePickPhoto "camera"
   ## User clicked CANCEL:
   if the result = "cancel" then
      exit mouseup
   end if
   
   ## We try to export the image to a JPG file:
   export last img to URL ("binfile:" & specialFolderPath("documents") & "/pic.jpg") as JPEG
   
   ## If the export fails for some reason, maybe we get some hint from THE RESULT
   if the result <> EMPTY then
      answer "Error while exporting image:" && the result
   end if
   ## Optional:
   --delete last img
end mouseUp

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: android - save the new camera picture

Post by Klaus » Sun Apr 29, 2018 6:23 pm

Please try with this syntax:
...
export last img to file (specialFolderPath("documents") & "/pic.jpg") as JPEG
...

Volkmar
Posts: 16
Joined: Thu Mar 22, 2018 6:24 pm

Re: android - save the new camera picture

Post by Volkmar » Sun Apr 29, 2018 6:41 pm

Thanks for your help...but it's the same result.

No error message, the picture will be make, but nothing saved.

Code: Select all

on mouseUp
   mobilePickPhoto "camera"
   ## User clicked CANCEL:
   if the result = "cancel" then
      exit mouseup
   end if
   
   ## We try to export the image to a JPG file:
   export last img to file (specialFolderPath("documents") & "/pic.jpg") as JPEG
   
   ## If the export fails for some reason, maybe we get some hint from THE RESULT
   if the result <> EMPTY then
      answer "Error while exporting image:" && the result
   end if
   ## Optional:
   --delete last img
end mouseUp

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

Re: android - save the new camera picture

Post by jacque » Sun Apr 29, 2018 8:47 pm

Where are you looking for the picture? The documents folder is local to the app, it is not public or visible in an Android file manager. If you get files(specialFolderPath("documents")) you should see it in the list. But if you look in the photo gallery it won't be there.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Volkmar
Posts: 16
Joined: Thu Mar 22, 2018 6:24 pm

Re: android - save the new camera picture

Post by Volkmar » Sun Apr 29, 2018 9:29 pm

Thanks a lot for the quick help.

Is it possible to save the picture in the android system, so i can found it, in the file manager or photo gallery?

In these way, I can also use the picture also by other android applications.

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

Re: android - save the new camera picture

Post by jacque » Mon Apr 30, 2018 4:24 pm

You can save the image to the public documents folder using specialFolderPath ("external documents") in the file path. Be sure you have selected the 'Write External Storage' permission in the Android standalone settings. Images stored there will be available to other apps.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

Klaus
Posts: 13824
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: android - save the new camera picture

Post by Klaus » Mon Apr 30, 2018 5:29 pm

Hallo Volkmar,
Volkmar wrote:
Sun Apr 29, 2018 9:29 pm
...
Is it possible to save the picture in the android system ... or photo gallery?
check "mobileExportImageToAlbum" in the dictionary, this will let you add an image to the users photo gallery!


Best

Klaus

Volkmar
Posts: 16
Joined: Thu Mar 22, 2018 6:24 pm

Re: android - save the new camera picture

Post by Volkmar » Tue May 01, 2018 1:30 am

Thanks for your support.

I found a solution. But not all gallery applications will show pictures out of all directories.

Code: Select all

   mobilePickPhoto "camera"
   set the defaultFolder to "/mnt/sdcard/DCIM/"
   put last image into url("binfile:" & milliseconds() & ".jpg")
But also the function "mobileExportImageToAlbum" has make a picture in the android directory. But I din't found the picture at these time, because my gallary application should only show picture from the adjusted / used library of the abdroid camera application. But nowadays I'm lucky with the code above.

Thank you very much again.

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”