Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Camera not found
Started by j_lancee Jul 26 2014 02:45 AM

5 replies to this topic
camera not found camera not found samples code listener capturephoto
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

j_lancee

[GLOBAL: userInfoPane.html]
j_lancee
  • Observer

  • 6 posts
  • Corona SDK

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
 
 


[TOPIC: post.html]
#2

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,660 posts
  • Enterprise

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



[TOPIC: post.html]
#3

j_lancee

[GLOBAL: userInfoPane.html]
j_lancee
  • Observer

  • 6 posts
  • Corona SDK

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!


[TOPIC: post.html]
#4

bjsorrentino

[GLOBAL: userInfoPane.html]
bjsorrentino
  • Veteran

  • 8,506 posts
  • Corona SDK

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



[TOPIC: post.html]
#5

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 25,660 posts
  • Enterprise

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



[TOPIC: post.html]
#6

j_lancee

[GLOBAL: userInfoPane.html]
j_lancee
  • Observer

  • 6 posts
  • Corona SDK

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




[topic_controls]
[/topic_controls]