media.capturePhoto() not appearing to call onComplete listener

Hello,

I am trying to capture a photo and display it using media.capturePhoto()

I don’t think the onComplete listener is firing. Here is the code;

 

-- Callback listener local function onPhotoComplete(event) local image = event.target if image then -- center image on screen image.x = halfW image.y = halfH end end -- Go to camera local function takePhoto( event ) if media.hasSource( media.Camera ) then media.capturePhoto( { listener = onPhotoComplete } ) else native.showAlert("Corona", "Camera not found.") end return true end -- Button to press for camera local btn = widget.newButton { width = profileHeight, height = profileHeight, left = leftPadding, top = halfH - profileHeight/2 - (heightOfFooter - heightOfHeader) /2, id = "profilePicture", defaultFile = userProfile["profilePicture"], onEvent = takePhoto }

I have been testing a variety of things, but can’t seem to get this to work. That is, display the image on screen or do anything in the onPhotoComplete listener.

I have tested on a HTC One and Galaxy Note II with no luck.

Thanks for any help,
Andy

Has anyone got any ideas or suggestions?

Can someone test the code I have provided on device?

You will need the android permissions in build.settings:
 

settings = { orientation = { default = "portrait", supported = { "portrait" } }, android = { usesPermissions = { "android.permission.INTERNET", "android.permission.CAMERA", "android.permission.WRITE\_EXTERNAL\_STORAGE", }, }, }

Thanks again
Andy

-- Button to press for camera local btn = widget.newButton { width = profileHeight, height = profileHeight, left = leftPadding, top = halfH - profileHeight/2 - (heightOfFooter - heightOfHeader) /2, id = "profilePicture", defaultFile = userProfile["profilePicture"], --onEvent = takePhoto } btn:addEventListener( "tap", takePhoto )

Setting an onEvent listener in widget was causing the problem.

Declaring a tap listener after the widget button creation was the solution

Has anyone got any ideas or suggestions?

Can someone test the code I have provided on device?

You will need the android permissions in build.settings:
 

settings = { orientation = { default = "portrait", supported = { "portrait" } }, android = { usesPermissions = { "android.permission.INTERNET", "android.permission.CAMERA", "android.permission.WRITE\_EXTERNAL\_STORAGE", }, }, }

Thanks again
Andy

-- Button to press for camera local btn = widget.newButton { width = profileHeight, height = profileHeight, left = leftPadding, top = halfH - profileHeight/2 - (heightOfFooter - heightOfHeader) /2, id = "profilePicture", defaultFile = userProfile["profilePicture"], --onEvent = takePhoto } btn:addEventListener( "tap", takePhoto )

Setting an onEvent listener in widget was causing the problem.

Declaring a tap listener after the widget button creation was the solution