Camera not found

Dear all,

I’m starting to developing an app in which I’m using the device’s camera. In the code for this app I used the standard code for taking a picture with the camera taken from the Samples > Camera app. In this Sample version the code is wrapped in a listener function that responds to a tap on the screen, as can be seen below. For my own app I removed this listener and just used:

My version: 

if media.hasSource( media.Camera ) then

media.capturePhoto( { listener = sessionComplete } )

else

native.showAlert(“Corona”, “Camera not found.”)

end

From Samples > Camera

local listener = function( event )

if media.hasSource( media.Camera ) then

media.capturePhoto( { listener = sessionComplete } )

else

native.showAlert(“Corona”, “Camera not found.”)

end

return true

end

bkgd:addEventListener( “tap”, listener )

Now this both works in the Corona simulator. However when I install both on my device, only the Samples app works. When I open up my app, it gives “Camera not found”. Anyone any idea how it can be that the device camera is not found in my version? Or any reason why the camera can not be found?

For the completeness of my story I copied the rest of my code (mostly taken from the Samples code with some things commented) below. I hope you can help, 

Thanks, Jules

Appendix - Rest of code:

local centerX = display.contentCenterX

local centerY = display.contentCenterY

local _W = display.contentWidth

local _H = display.contentHeight

– Camera not supported on simulator.                    

local isXcodeSimulator = “iPhone Simulator” == system.getInfo(“model”)

if (isXcodeSimulator) then

local alert = native.showAlert( “Information”, “Camera API not available on iOS Simulator.”, { “OK”})    

end

local bkgd = display.newRect( centerX, centerY, _W, _H )

bkgd:setFillColor( 0.5, 0, 0 )

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 = centerX

image.y = centerY

 

end

end

Are you doing this on iOS or Android?  If Android, do you have the right permissions in your build.settings that allows access to the camera?

Rob

Thank you for your suggestion. I use Android and I did include permission for the camera.

In my build.settings the following lines are present:

– Android permissions

androidPermissions = {

  “android.permission.INTERNET”,

  “android.permission.CAMERA”,

  },

So thanks for the suggestion, but any other ideas? Still the app gives the same error : Camera not found.

I hope to hear from you!

Hi @j_lancee,

Can you please re-format your build.settings in the structure that we show here, under “Android Build Settings”?

http://docs.coronalabs.com/guide/distribution/buildSettings/index.html#androidsettings

Thanks,

Brent

Also can you build the Camera sample app and see if that works for you?

Thanks again, I did both things, and it opens up the camera now, so it can find it! Thanks!

Are you doing this on iOS or Android?  If Android, do you have the right permissions in your build.settings that allows access to the camera?

Rob

Thank you for your suggestion. I use Android and I did include permission for the camera.

In my build.settings the following lines are present:

– Android permissions

androidPermissions = {

  “android.permission.INTERNET”,

  “android.permission.CAMERA”,

  },

So thanks for the suggestion, but any other ideas? Still the app gives the same error : Camera not found.

I hope to hear from you!

Hi @j_lancee,

Can you please re-format your build.settings in the structure that we show here, under “Android Build Settings”?

http://docs.coronalabs.com/guide/distribution/buildSettings/index.html#androidsettings

Thanks,

Brent

Also can you build the Camera sample app and see if that works for you?

Thanks again, I did both things, and it opens up the camera now, so it can find it! Thanks!