Camera Sample App (Help!)

Good afternoon coders! I have a slight problem that isn’t as easy as i thought it would be to solve. I am pretty sure you are all familiar with the Corona SDK Sample Apps< Camera app which is the following code:

-- Camera not supported on simulator. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; local isXcodeSimulator = "iPhone Simulator" == system.getInfo("model") if (isXcodeSimulator) then &nbsp;&nbsp;&nbsp;&nbsp; local alert = native.showAlert( "Information", "Camera API not available on iOS Simulator.", { "OK"}) &nbsp; &nbsp; end -- local bkgd = display.newRect( 0, 0, display.contentWidth, display.contentHeight ) bkgd:setFillColor( 128, 0, 0 ) local text = display.newText( "Tap anywhere to launch Camera", 0, 0, nil, 16 ) text:setTextColor( 255, 255, 255 ) text.x = 0.5 \* display.contentWidth text.y = 0.5 \* display.contentHeight local sessionComplete = function(event)&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;local image = event.target &nbsp;&nbsp;&nbsp;&nbsp;print( "Camera ", ( image and "returned an image" ) or "session was cancelled" ) &nbsp;&nbsp;&nbsp;&nbsp;print( "event name: " .. event.name ) &nbsp;&nbsp;&nbsp;&nbsp;print( "target: " .. tostring( image ) ) &nbsp;&nbsp;&nbsp;&nbsp;if image then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-- center image on screen &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;image.x = display.contentWidth/2 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;image.y = display.contentHeight/2 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local w = image.width &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;local h = image.height &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print( "w,h = ".. w .."," .. h ) &nbsp;&nbsp;&nbsp;&nbsp;end end local listener = function( event ) &nbsp;&nbsp;&nbsp;&nbsp;if media.hasSource( media.Camera ) then &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;media.show( media.Camera, sessionComplete ) &nbsp;&nbsp;&nbsp;&nbsp;else &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;native.showAlert("Corona", "Camera not found.") &nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;&nbsp;&nbsp;return true end bkgd:addEventListener( "tap", listener ) &nbsp;

My problem is this: How can I use this code but DO NOT have to press the screen for the camera to appear. Basically I just want to open the app and instantly go to the camera view, how may I go about this or is it possible on Corona?

Thanks for any responses, gladly appreciated! Keep on coding !

  • Julian

Just use this code:

local sessionComplete = function(event) local image = event.target print( "Camera ", ( image and "returned an image" ) or "session was cancelled" ) print( "event name: " .. event.name ) print( "target: " .. tostring( image ) ) if image then -- center image on screen image.x = display.contentWidth/2 image.y = display.contentHeight/2 local w = image.width local h = image.height print( "w,h = ".. w .."," .. h ) end end media.show( media.Camera, sessionComplete )

There will be no check to see if the device has a camera or anything.  But that should just go right to the camera.

Thanks for the reply, much appreciated! The code exercised perfectly. Does Corona support the function to be able to save the image onto the phone album? Or does Android not allow that access with Corona? Thanks again!

Just use this code:

local sessionComplete = function(event) local image = event.target print( "Camera ", ( image and "returned an image" ) or "session was cancelled" ) print( "event name: " .. event.name ) print( "target: " .. tostring( image ) ) if image then -- center image on screen image.x = display.contentWidth/2 image.y = display.contentHeight/2 local w = image.width local h = image.height print( "w,h = ".. w .."," .. h ) end end media.show( media.Camera, sessionComplete )

There will be no check to see if the device has a camera or anything.  But that should just go right to the camera.

Thanks for the reply, much appreciated! The code exercised perfectly. Does Corona support the function to be able to save the image onto the phone album? Or does Android not allow that access with Corona? Thanks again!