Having problems with getting photo in Android

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

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

mrcoollion
Posts: 738
Joined: Thu Sep 11, 2014 1:49 pm

Having problems with getting photo in Android

Post by mrcoollion » Thu Sep 11, 2014 1:59 pm

Maybe I am doing it wrong but I cannot seem to get mobilePickPhoto to work correct on android.
My camera gets active and I can take the photo but after selecing save I get an error in my stack.

I made a test Stack for learning puposes based on the existing tutorials and what I have found in this forum but nothing seems to work.
So here is my cry for help.
The button code is shown below. In the attachment is the test stack I made.

Regards,

Paul

================================
on mouseUp
# the X, Y dimensions for an image are not supported on Android and are ignored
global tEnvironment,tPlatform
switch tPlatform
case "android"
# When a picture is taken using mobilpicphoto it creates a new "image" object to contain the picture.
set the name of the templateimage to "TheTakenPicture" // The templateimage is just that. A template for the image object. When you set properties for the templateimage and then create a new image object it uses the settings you specified. So in the case of this really cool script, it sets the location (loc) of the template image to a hidden spot off screen. So when the picture is taken it appears in that location.
set the loc of the templateimage to -1000,-1000 // Will hide the image offscreen in this case I want to see it therefore I place into the image object: image "The_Image" .
# set the vis of the templateImage to false // This is an alternative way to hide the taken image if you do not want it to show immediately on the card.
set the width of the templateImage to 294 // Image Size. A way to set X, Y dimensions for an image in android devices
set the height of the templateImage to 238 // Image Size. A way to set X, Y dimensions for an image in android devices
mobilePickPhoto "camera" // Opens the device camera software and lets you take a picture after which it goes bach to your card.
break
case "iOS"
mobilePickPhoto "camera", 294, 238
break
case "Win32"
Answer "You have just simulated taking a picture with the Default Cam"
break
end switch
if the result is empty // IF 01
then // IF 01

# Put the last image into image "The_Image" // This statement does not work ?? Camera can take picture but then the result is error. According to tutorial this should work?
set the text of image "The_Image" to the last image of this card // I already have an empty image object ("The_Image") to hold the data. When you set the text of image "The_Image" to the text of another image it copies the data from one image (in this case the last image taken & autosaved) and stuffs it into the other.
set the visible of image "The_Image" to true
wait 0 millisecs with messages #Wait 0 seconds with messages (again, read up on it in the dictionary) is what it appears to be. The current handler is paused. The "with messages" part means that other things waiting in the message queue can be worked on while waiting.

# Save image in a personal specified location as PNG
set the defaultfolder to specialfolderpath("documents")
export image "The_Image" of this card to URL("binfile:" & "./" & "tempic" ) as PNG // relative pathing with defaultfolder. in a path . means the current folder (so whatever the defaultfolder is set to) .. would mean up 1 folder. So, since the defaultfolder is already pointing to the documents folder, putting a file in ./filename.png will create a file named filename.png in the users documents folder.
# URL means you are going to define what type of data transfer it is, in this case its a binary file. (like on the web, http: is a hypertext transfer protocol page, ftp: is file transfer protocol) LC has file: and binfile: So you are exporting the image to URL of type binfile:

put the last image into tAttachment["data"] // Put image into a aray variable (E.G. for saving into a database)
put "image/jpeg" into tAttachment["type"]
put "CamDefaultPicture" into tAttachment["name"]
delete the last image of this card // Since no new images have been created, the "delete the last image of this card" line will remove it.
mobileExportImageToAlbum tAttachment["data"] //Other way to save the captured image in
mobileComposeMail "Camera Example", getRecipient(),,,, tAttachment // Send Image via E-Mail

else // IF 01
put the result into field "The_Result" // Show whats in the result if not empty
Answer "There is a problem with mobilePickPhoto command, the result is :" & the result
end if // IF 01
end mouseUp

=====================================

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Having problems with getting photo in Android

Post by Klaus » Thu Sep 11, 2014 2:17 pm

Hi mrcoollion,

1. welcome to the forum! :D
2. Unfortunately you need to have at least 10 postings before you can add attachments, so your stack is not visible here.
3. WHAT errors do you get when trying to save the photo?

Try not NOT set the defaultfolder, you can create teh complete and abolute pathname without problems:
...
put specialfolderpath("documents") & "/tempic" into tImagePath

## But here is the culprit: wrong syntax! 8)
## Please refer to the dictionary if something like this happens to check the syntax!
## export image "The_Image" of this card to URL("binfile:" & "tImagePath ) as PNG
export image "The_Image" of this card TO FILE tImagePath as PNG
...

And check this, from the dictionary about "mobilepickphoto":
Note: Android: mobilePickPhoto requires 'Camera' and 'External Storage' permissions.
Set these in the standalone application settings pane.
Not setting this permission will result in a "could not create temporary image file" error.

Best

Klaus

mrcoollion
Posts: 738
Joined: Thu Sep 11, 2014 1:49 pm

Re: Having problems with getting photo in Android

Post by mrcoollion » Thu Sep 11, 2014 3:09 pm

Hi Klaus,

Thanks a million for helping me.
I changed the code according to your suggestions (also took some out to make it easier for you to read).
But still the result is error (no other text or explanation). I see error in field "The_Result" just before the camera gets active. It does not seem to wait until the photo is saved ?!

Here is the cleaned-up code I tested with, but it still gives as a result: error

-------------------------------------------------
on mouseUp
set the name of the templateimage to "TheTakenPicture"
set the visible of the templateImage to false
set the width of the templateImage to 294
set the height of the templateImage to 238
mobilePickPhoto "camera"

if the result is empty // IF 01
then // IF 01
set the text of image "The_Image" to the last image of this card // I already have an empty image object on my card ("The_Image") .
set the visible of image "The_Image" to true // I want to see the image on my card
wait 0 millisecs with messages

# Save image in a personal specified location as PNG
put specialfolderpath("documents") & "/tempic" into tImagePath
export image "The_Image" of this card TO FILE tImagePath as PNG

put the last image into tAttachment["data"] // Put image into a aray variable (E.G. for saving into a database)
put "image/jpeg" into tAttachment["type"]
put "CamDefaultPicture" into tAttachment["name"]
delete the last image of this card
mobileExportImageToAlbum tAttachment["data"]

else // IF 01
put the result into field "The_Result" // Show whats in the result if not empty
Answer "There is a problem with mobilePickPhoto command, the result is :" & the result
end if // IF 01

end mouseUp
Last edited by mrcoollion on Thu Sep 11, 2014 3:57 pm, edited 1 time in total.

mrcoollion
Posts: 738
Joined: Thu Sep 11, 2014 1:49 pm

Re: Having problems with getting photo in Android

Post by mrcoollion » Thu Sep 11, 2014 3:13 pm

Settings2.jpg
Settings1.jpg
Images of my settings

newtronsols
Posts: 192
Joined: Tue Mar 11, 2014 12:57 pm

Re: Having problems with getting photo in Android

Post by newtronsols » Thu Sep 11, 2014 4:26 pm

Example in Quality control centre appears as:
[http://quality.runrev.com/show_bug.cgi?id=11118]

answer "Get product photo from:" with "Camera" or "Library"
switch it
case "Library"
mobilePickPhoto "library"
lock screen
put last image into product_new
set the text of image "product_photo.png" to product_new
delete last image
unlock screen
break
case "Camera"
mobilePickPhoto "camera" --"rear camera" gets activated by default
lock screen
put last image into product_new
set the text of image "product_photo.png" to product_new
delete last image
unlock screen
break
end switch
Last edited by newtronsols on Thu Sep 11, 2014 4:38 pm, edited 1 time in total.

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Having problems with getting photo in Android

Post by Klaus » Thu Sep 11, 2014 4:31 pm

Hi newtronsols ,

hmm, syntax is correct!?

Try to isolate the problem and leave out the mail stuff for now:

Code: Select all

on mouseUp
   set the name of the templateimage to "TheTakenPicture" 
   set the visible of the templateImage to false
   set the width of the templateImage to 294 
   set the height of the templateImage to 238 
   mobilePickPhoto "camera" 
   
   ## Just like IT "the result" can also change its content when you don't exspect it, so put it into a variable first!
   put the result into tResult
   
   if tResult = empty then // IF 01
      set the text of image "The_Image" to the TEXT Of last image of this card
      set the visible of image "The_Image" to true
      wait 0 millisecs with messages 
      
      # Save image in a personal specified location as PNG
      put specialfolderpath("documents") & "/tempic" into tImagePath
      export image "The_Image" TO FILE tImagePath as PNG
      
      #      put the last image into tAttachment["data"] // Put image into a aray variable (E.G. for saving into a database)
      #      put "image/jpeg" into tAttachment["type"]
      #      put "CamDefaultPicture" into tAttachment["name"]
      #      delete the last image of this card 
      #      mobileExportImageToAlbum tAttachment["data"] 
      
   else // IF 01
      put tResult into field "The_Result" // Show whats in the result if not empty
      Answer "There is a problem with mobilePickPhoto command, the result is :" & tResult 
   end if // IF 01
end mouseUp
The see what fld "The_result" shows, maybe make the field bigger to display the complete error text!?

And maybe you should also check INTERNET in the standalone builder settings for the mail stuff?B first lets get the snapshot to work!


Best

Klaus

newtronsols
Posts: 192
Joined: Tue Mar 11, 2014 12:57 pm

Re: Having problems with getting photo in Android

Post by newtronsols » Thu Sep 11, 2014 4:40 pm

I was putting code to test for an answer.

My problem is:

http://forums.livecode.com/viewtopic.php?f=73&t=21414

But it may be part of my answer. put last image into. & set the text of image "product_photo.png" to product_new. Would that be a way to proceed with the photo for a phone contact?
Last edited by newtronsols on Thu Sep 11, 2014 5:12 pm, edited 2 times in total.

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Having problems with getting photo in Android

Post by Klaus » Thu Sep 11, 2014 4:44 pm

newtronsols wrote:I was putting code to test for an answer.
Sorry, I meant of course Mr. mrcoollion in my posting, you posted while I was writing :D

newtronsols
Posts: 192
Joined: Tue Mar 11, 2014 12:57 pm

Re: Having problems with getting photo in Android

Post by newtronsols » Thu Sep 11, 2014 4:48 pm

deleted see previous
Last edited by newtronsols on Thu Sep 11, 2014 6:47 pm, edited 2 times in total.

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Having problems with getting photo in Android

Post by Klaus » Thu Sep 11, 2014 5:06 pm

Hi newtronsols,
newtronsols wrote:My problem is:
viewtopic.php?f=73&t=21414
But it may be part of my answer. put last image into... a named x.png image and then rename the image, curious.
Would that be a way to proceed with the photo for a phone contact?
1. are you able to post a clickable URL? If yes, please do!

2. You are obviously hijacking this thread, not nice! 8)
Your problem is completely different!


Best

Klaus

newtronsols
Posts: 192
Joined: Tue Mar 11, 2014 12:57 pm

Re: Having problems with getting photo in Android

Post by newtronsols » Thu Sep 11, 2014 5:18 pm

Look up a few posts.

Also tried on:

http://stackoverflow.com/questions/2571 ... roid?stw=2

P.s. I wasn't hijacking I was trying to help and then suddenly thought it could be part of my answer.

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Having problems with getting photo in Android

Post by Klaus » Thu Sep 11, 2014 5:34 pm

Getting an error when trying to EXPORT an image has nothing to do with the missing "photo" key in the "mobileGetContactData"! 8)
See my anser to that question in your original thread!

mrcoollion
Posts: 738
Joined: Thu Sep 11, 2014 1:49 pm

Re: Having problems with getting photo in Android

Post by mrcoollion » Thu Sep 11, 2014 6:26 pm

Hi Guy's
Thx newtronsols but I tried all codes from scratch. Still get error.

Tried the sample stack from
.......show_bug.cgi?id=11118

Also gives error but does not crash.
Using Livecode : LiveCode Community 7.0 (rc 1) on Windows 7
Testing on SamSung Galaxy S3 GT-I9300 with Android version 4.3

I am at a loss....
Here are my Standalone Application Settings
SettingsBug02.jpg
SettingsBug01.jpg

sefrojones
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 447
Joined: Mon Jan 23, 2012 12:46 pm

Re: Having problems with getting photo in Android

Post by sefrojones » Thu Sep 11, 2014 6:33 pm

MobilePickPhoto is broken in LC 7.0 :

http://quality.runrev.com/show_bug.cgi?id=13329




It is working in LC 6.7 RC1 and back.

--Sefro

edit: I'll also add, that if you are working on an application that you plan on releasing, it is recommended to us the most recent stable (GM) version.

newtronsols
Posts: 192
Joined: Tue Mar 11, 2014 12:57 pm

Re: Having problems with getting photo in Android

Post by newtronsols » Thu Sep 11, 2014 6:59 pm

I'm using Livecode 6.7 (dp4) [correction moved to rc2] commercial on Windows 7 - so far, this seems to be the most stable for android. Test builds very quickly to my Android phone via usb.
I don't know if 6.7 (dp4 - now rc2) community is the same code?
Last edited by newtronsols on Wed Sep 24, 2014 8:32 pm, edited 2 times in total.

Post Reply