[Resolved] Camera not showing with media.show - why?

Hi,

I got the following code from the docs and I created an app with just this and loaded it on my Android phone. The camera does not come up. Is there a better way to do this?

Thanks!

local onComplete = function(event)  
 local photo = event.target  
 print( "photo w,h = " .. photo.width .. "," .. photo.height )  
end  
media.show( media.Camera, onComplete )  

[import]uid: 184193 topic_id: 32620 reply_id: 332620[/import]

Does the camera app appear or does it say no camera installed ?

You need this in your build settings -

androidPermissions = {
“android.permission.CAMERA”,
“android.permission.WRITE_EXTERNAL_STORAGE”,
},

Dave [import]uid: 117617 topic_id: 32620 reply_id: 129764[/import]

I actually had other code to check if the camera was available and it said no camera installed. This code I show above does not say anything because it is not checking. But I did not put the permissions in it. The example did not show to do that but I thought about it after I made the post last night. So I will add this in and give it a try.

When I take a picture can i save it to the system.ResourceDirectory which is where the app is running? And can i set the name of the image file?

Thanks!

Warren
[import]uid: 184193 topic_id: 32620 reply_id: 129765[/import]

Camera still not working. I keep getting “This device does not have a camera”. I updated the Build file also. Can you tell me if I have something wrong? Here is what I have:

Build file:

-- Supported values for orientation:  
-- portrait, portraitUpsideDown, landscapeLeft, landscapeRight  
  
settings = {  
  
 orientation = {  
 default = "portrait",  
 supported = { "portrait", }  
 },  
  
 iphone = {  
 plist = {  
 UIStatusBarHidden = false,  
 UIPrerenderedIcon = true, -- set to false for "shine" overlay  
 --UIApplicationExitsOnSuspend = true, -- uncomment to quit app on suspend  
  
 --[[  
 -- iOS app URL schemes:  
 CFBundleURLTypes =  
 {  
 {  
 CFBundleURLSchemes =  
 {  
 "fbXXXXXXXXXXXXXX", -- example scheme for facebook  
 "coronasdkapp", -- example second scheme  
 }  
 }  
 }  
 --]]  
 }  
 },  
  
 --[[  
 -- Android permissions  
  
 androidPermissions = {  
 "android.permission.INTERNET",  
 "android.permission.CAMERA",  
 "android.permission.WRITE\_EXTERNAL\_STORAGE",  
 },  
  
 ]]--  
}  

Main file:

-----------------------------------------------------------------------------------------  
--  
-- main.lua  
--  
-----------------------------------------------------------------------------------------  
  
-- Your code here  
local onComplete = function(event)  
 local photo = event.target  
 print( "photo w,h = " .. photo.width .. "," .. photo.height )  
end  
  
if media.hasSource( media.Camera ) then  
 media.show( media.Camera, onComplete )  
else  
 native.showAlert( "Corona", "This device does not have a camera.", { "OK" } )  
end  

[import]uid: 184193 topic_id: 32620 reply_id: 129779[/import]

Your Android settings are commented out in the build file, do you realise that ?

Dave [import]uid: 117617 topic_id: 32620 reply_id: 129782[/import]

Also, I am running the trial version 2012.894 (2012.7.27) on Windows. It should be working though right?

Thanks
[import]uid: 184193 topic_id: 32620 reply_id: 129785[/import]

Does the camera app appear or does it say no camera installed ?

You need this in your build settings -

androidPermissions = {
“android.permission.CAMERA”,
“android.permission.WRITE_EXTERNAL_STORAGE”,
},

Dave [import]uid: 117617 topic_id: 32620 reply_id: 129764[/import]

Can you show me what to uncomment? Can you paste it in a reply with the comments taken out?

Thanks!

Its my first time modifying the file.
[import]uid: 184193 topic_id: 32620 reply_id: 129786[/import]

I actually had other code to check if the camera was available and it said no camera installed. This code I show above does not say anything because it is not checking. But I did not put the permissions in it. The example did not show to do that but I thought about it after I made the post last night. So I will add this in and give it a try.

When I take a picture can i save it to the system.ResourceDirectory which is where the app is running? And can i set the name of the image file?

Thanks!

Warren
[import]uid: 184193 topic_id: 32620 reply_id: 129765[/import]

I did this and still not working:

-- Supported values for orientation:  
-- portrait, portraitUpsideDown, landscapeLeft, landscapeRight  
  
settings = {  
  
 orientation = {  
 default = "portrait",  
 supported = { "portrait", }  
 },  
  
 iphone = {  
 plist = {  
 UIStatusBarHidden = false,  
 UIPrerenderedIcon = true, -- set to false for "shine" overlay  
 --UIApplicationExitsOnSuspend = true, -- uncomment to quit app on suspend  
  
 --[[  
 -- iOS app URL schemes:  
 CFBundleURLTypes =  
 {  
 {  
 CFBundleURLSchemes =  
 {  
 "fbXXXXXXXXXXXXXX", -- example scheme for facebook  
 "coronasdkapp", -- example second scheme  
 }  
 }  
 }  
 --]]  
 }  
 },  
  
 [[  
 -- Android permissions  
  
 androidPermissions = {  
 "android.permission.CAMERA",  
 },  
  
 ]]  
}  

[import]uid: 184193 topic_id: 32620 reply_id: 129787[/import]

Get rid of the [[and]] around the Android stuff.

I have a full iOS version of Corona but only a trial Android and it works fine on my sons Nexus 7. I was getting the same error as you but added them lines in build settings and it started working.

EDIT, here is my build file (my code in the app is identical to yours) -

settings = {  
  
 orientation = {  
 default = "landscapeRight",  
 supported = { "landscapeRight","landscapeLeft" }  
 },  
  
 iphone = {  
 plist = {  
 CoronaUseIOS6IPadPhotoPickerLandscapeOnlyWorkaround = true,  
 UIStatusBarHidden = true,  
 UIPrerenderedIcon = true, -- set to false for "shine" overlay  
 UIApplicationExitsOnSuspend = false,  
 CFBundleIconFile = "Icon.png",  
 CFBundleIconFiles = {  
 "Icon.png" ,  
 "Icon@2x.png" ,  
 "Icon-72.png" ,  
 "Icon-72@2x.png" ,  
 "Icon-Small-50.png" ,  
 "Icon-Small-50@2x.png" ,  
 "Icon-Small.png" ,  
 "Icon-Small@2x.png" ,  
 },  
 CFBundleURLTypes = {  
 {  
 CFBundleURLSchemes =  
 {  
 "fbREMOVED",  
 }  
 }  
 }  
 }  
 },  
  
 --For Android:  
 androidPermissions = {  
 "android.permission.CAMERA",  
 "android.permission.WRITE\_EXTERNAL\_STORAGE",  
 },  
}  

Dave [import]uid: 117617 topic_id: 32620 reply_id: 129789[/import]

Yeah!!! It works! The camera came right up and let me take a pic and then it was shown. Perfect! Now I can work with the other properties. I will need to save the picture software and then I want to post it to Facebook with the Facebook calls.

Warren
[import]uid: 184193 topic_id: 32620 reply_id: 129792[/import]

Camera still not working. I keep getting “This device does not have a camera”. I updated the Build file also. Can you tell me if I have something wrong? Here is what I have:

Build file:

-- Supported values for orientation:  
-- portrait, portraitUpsideDown, landscapeLeft, landscapeRight  
  
settings = {  
  
 orientation = {  
 default = "portrait",  
 supported = { "portrait", }  
 },  
  
 iphone = {  
 plist = {  
 UIStatusBarHidden = false,  
 UIPrerenderedIcon = true, -- set to false for "shine" overlay  
 --UIApplicationExitsOnSuspend = true, -- uncomment to quit app on suspend  
  
 --[[  
 -- iOS app URL schemes:  
 CFBundleURLTypes =  
 {  
 {  
 CFBundleURLSchemes =  
 {  
 "fbXXXXXXXXXXXXXX", -- example scheme for facebook  
 "coronasdkapp", -- example second scheme  
 }  
 }  
 }  
 --]]  
 }  
 },  
  
 --[[  
 -- Android permissions  
  
 androidPermissions = {  
 "android.permission.INTERNET",  
 "android.permission.CAMERA",  
 "android.permission.WRITE\_EXTERNAL\_STORAGE",  
 },  
  
 ]]--  
}  

Main file:

-----------------------------------------------------------------------------------------  
--  
-- main.lua  
--  
-----------------------------------------------------------------------------------------  
  
-- Your code here  
local onComplete = function(event)  
 local photo = event.target  
 print( "photo w,h = " .. photo.width .. "," .. photo.height )  
end  
  
if media.hasSource( media.Camera ) then  
 media.show( media.Camera, onComplete )  
else  
 native.showAlert( "Corona", "This device does not have a camera.", { "OK" } )  
end  

[import]uid: 184193 topic_id: 32620 reply_id: 129779[/import]

Your Android settings are commented out in the build file, do you realise that ?

Dave [import]uid: 117617 topic_id: 32620 reply_id: 129782[/import]

Also, I am running the trial version 2012.894 (2012.7.27) on Windows. It should be working though right?

Thanks
[import]uid: 184193 topic_id: 32620 reply_id: 129785[/import]

Can you show me what to uncomment? Can you paste it in a reply with the comments taken out?

Thanks!

Its my first time modifying the file.
[import]uid: 184193 topic_id: 32620 reply_id: 129786[/import]

I did this and still not working:

-- Supported values for orientation:  
-- portrait, portraitUpsideDown, landscapeLeft, landscapeRight  
  
settings = {  
  
 orientation = {  
 default = "portrait",  
 supported = { "portrait", }  
 },  
  
 iphone = {  
 plist = {  
 UIStatusBarHidden = false,  
 UIPrerenderedIcon = true, -- set to false for "shine" overlay  
 --UIApplicationExitsOnSuspend = true, -- uncomment to quit app on suspend  
  
 --[[  
 -- iOS app URL schemes:  
 CFBundleURLTypes =  
 {  
 {  
 CFBundleURLSchemes =  
 {  
 "fbXXXXXXXXXXXXXX", -- example scheme for facebook  
 "coronasdkapp", -- example second scheme  
 }  
 }  
 }  
 --]]  
 }  
 },  
  
 [[  
 -- Android permissions  
  
 androidPermissions = {  
 "android.permission.CAMERA",  
 },  
  
 ]]  
}  

[import]uid: 184193 topic_id: 32620 reply_id: 129787[/import]

Get rid of the [[and]] around the Android stuff.

I have a full iOS version of Corona but only a trial Android and it works fine on my sons Nexus 7. I was getting the same error as you but added them lines in build settings and it started working.

EDIT, here is my build file (my code in the app is identical to yours) -

settings = {  
  
 orientation = {  
 default = "landscapeRight",  
 supported = { "landscapeRight","landscapeLeft" }  
 },  
  
 iphone = {  
 plist = {  
 CoronaUseIOS6IPadPhotoPickerLandscapeOnlyWorkaround = true,  
 UIStatusBarHidden = true,  
 UIPrerenderedIcon = true, -- set to false for "shine" overlay  
 UIApplicationExitsOnSuspend = false,  
 CFBundleIconFile = "Icon.png",  
 CFBundleIconFiles = {  
 "Icon.png" ,  
 "Icon@2x.png" ,  
 "Icon-72.png" ,  
 "Icon-72@2x.png" ,  
 "Icon-Small-50.png" ,  
 "Icon-Small-50@2x.png" ,  
 "Icon-Small.png" ,  
 "Icon-Small@2x.png" ,  
 },  
 CFBundleURLTypes = {  
 {  
 CFBundleURLSchemes =  
 {  
 "fbREMOVED",  
 }  
 }  
 }  
 }  
 },  
  
 --For Android:  
 androidPermissions = {  
 "android.permission.CAMERA",  
 "android.permission.WRITE\_EXTERNAL\_STORAGE",  
 },  
}  

Dave [import]uid: 117617 topic_id: 32620 reply_id: 129789[/import]

Yeah!!! It works! The camera came right up and let me take a pic and then it was shown. Perfect! Now I can work with the other properties. I will need to save the picture software and then I want to post it to Facebook with the Facebook calls.

Warren
[import]uid: 184193 topic_id: 32620 reply_id: 129792[/import]