Camera on Android Nexus S not returning

Hello All,

I’ve hit a problem that seems to be plaguing my poor little Nexus S. I was attempting to capture an image via the built-in Android Camera application using the latest daily build (2012.846) but it seems that the camera app never correctly returns back to my application.

I am using storyboard, but even the sample camera application doesn’t work for me:

[lua]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

local listener = function( event )
if media.hasSource( media.Camera ) then
media.show( media.Camera, sessionComplete )
else
native.showAlert(“Corona”, “Camera not found.”)
end
return true
end
bkgd:addEventListener( “tap”, listener )[/lua]

This will correctly open the Camera app and allow me take a picture. I then accept the preview but it just returns to the application with no response. No image displayed (in the sample) and in my actual application it doesn’t even trigger the equivalent sessionComplete listener.

I’m wondering if it is something to do with support for application suspension and the return back to the Corona activity. Nothing strange seems to be coming out of ADB either, so I’m at a loss without a chance to browse further debug messages. [import]uid: 122384 topic_id: 28479 reply_id: 328479[/import]

I just tested our sample app “Media/Camera” that is included with the Corona SDK on our Nexus S and it worked. I tried it with build 840 and 846. The device is running Android OS version 2.3.6.

I don’t think this is a Corona bug. If there was a permissions issue, then it would have been logged and an alert message would have been shown. I think there is either something wrong with the Camera app that you are using (is it 3rd party?) or perhaps the device is out of storage space… in which case it is up to the camera app to inform the user about storage issues.

Are there any other clues that you can find? Have a look at external storage and make sure that there is enough space on your device for a large photo. Also, put a simple [lua]print()[/lua] statement at the very top of your Lua listener to make sure a Lua runtime error is not causing your script to bail out of the listener… although “adb logcat” should log such an error. [import]uid: 32256 topic_id: 28479 reply_id: 115067[/import]

Thanks for the reply Joshua.

The camera app is not 3rd party, no, it’s the standard Android camera app. I also checked the storage amount and there are still 13GBs left over, so not likely to be that.

I did have a [lua]print()[/lua] statement right at the top of the listener and no, there was no clear error.

One thing I noticed about what you said though, that you tested against 2.3.6, I’m working on ICS (4.0.4). One thing I didn’t consider is the level of support that Corona has for the most recent versions of the Android OS. Do you have a device available with a similar Android OS version (ICS/4.0.X)? Or are there limits to the Corona SDK support dependent on the OS version?

Thanks [import]uid: 122384 topic_id: 28479 reply_id: 115073[/import]

I just re-tested our “Camera” sample app on the following devices:

  • Galaxy Nexus with Android OS 4.0.4
  • Nexus 7 with Android OS 4.1

The camera API worked. The camera shot was successfully transferred to Corona and the Lua listener was invoked. So, we still can’t reproduce this issue.

It’s possible that this is a device specific issue. The problem here is that there is no standard camera app on Android. Every device manufacturer provides their own camera app… along with their own camera drivers which sometimes have inconsistent behaviors or even buggy implementations.

We do provide a custom camera activity in Corona as a fallback mechanism in case a camera app or external storage could not be found on the device. In order to use it, you will need to remove the “android.permission.WRITE_EXTERNAL_STORAGE” permission from your “build.settings” file. This would mean that if you want to save the camera shot, you will need to do it yourself via [lua]display.save()[/lua] or use the save-to-file option in [lua]media.show()[/lua]. [import]uid: 32256 topic_id: 28479 reply_id: 115189[/import]

Thanks for the continued advice.

I’m going to revert back to Android SDK for the development of this particular app, next one will be back in Corona. [import]uid: 122384 topic_id: 28479 reply_id: 115323[/import]

Okay. I’m sorry you have to do that… but I understand you’ve got to do whatever it takes to make your app work and it’s nothing personal.

If you spot anything unusual about your device’s Camera app, such as a non-standard result being provided to your activity’s onActivityResult() method or perhaps a non-standard intent setup, then would you mind letting us know please? [import]uid: 32256 topic_id: 28479 reply_id: 115435[/import]