[TIMOB-16199] Android: camera with overlay takePicture() firing success function multiple times
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2014-07-07T22:33:08.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 3.4.0 |
Components | n/a |
Labels | android, camera, module_media, qe-manualtest, regression |
Reporter | Mike Fogg |
Assignee | Ping Wang |
Created | 2014-01-09T19:25:51.000+0000 |
Updated | 2016-08-12T14:45:26.000+0000 |
Description
The takePicture() function on Android is firing the success function multiple (3) times when using a custom camera overlay. Example:
app.js
// Containing window
var win = Ti.UI.createWindow({
navBarHidden: true,
backgroundColor: "#ffffff",
height: Ti.UI.FILL,
width: Ti.UI.FILL
});
// Blue button that opens the camera
var open_camera = Ti.UI.createButton({
height: Ti.UI.SIZE,
width: Ti.UI.SIZE,
bottom: 50,
title: 'Camera'
});
// Adding the "open camera" button
win.add(open_camera);
// Function to show the camera
function openCamera(){
alert('opening');
open_camera.backgroundColor = "#00ff00"; // Just checking if we got here
// The camera overlay I want displayed over the camera
var camera_overlay = Ti.UI.createView({
top: 0,
left: 0,
height: Ti.UI.FILL,
width: Ti.UI.FILL
});
var take_picture = Ti.UI.createButton({
height: Ti.UI.SIZE,
width: Ti.UI.SIZE,
bottom: 50,
title: 'Take Picture'
});
take_picture.addEventListener('click', function () {
Ti.Media.takePicture();
});
camera_overlay.add(take_picture);
// The actual show camera part
Ti.Media.showCamera({
success:function(e)
{
alert('success'); // I want this!
},
cancel:function(e)
{
},
error:function(error)
{
},
autohide: false,
showControls: false,
mediaTypes: [Ti.Media.MEDIA_TYPE_PHOTO],
overlay: camera_overlay // The camera overlay being added to camera view
});
};
// Click event to show the camera
open_camera.addEventListener("click", function(e){
openCamera();
});
// Open the window
win.open();
log:
[INFO] : I/dalvikvm-heap: Grow heap (frag case) to 17.483MB for 1811991-byte allocation
[INFO] : ALERT: (KrollRuntimeThread) [6602,83973] success
[INFO] : I/dalvikvm-heap: Grow heap (frag case) to 19.187MB for 1363520-byte allocation
[INFO] : ALERT: (KrollRuntimeThread) [248,84221] success
[INFO] : I/dalvikvm-heap: Grow heap (frag case) to 20.975MB for 1830730-byte allocation
[INFO] : ALERT: (KrollRuntimeThread) [281,84502] success
Reference: [http://developer.appcelerator.com/question/161324/android-camera-taking-3-pictures-at-a-time]
I was not able to reproduce this issue on Samsung Galaxy Nexus device so it may be device specific. Would you be able to try it on another device? I see the success alert only once after I take the picture.
@Ritu, I just tested the same code on an HTC EVO 4G and it worked fine (only saw success once). The software on this version is 2.3.5 so it's really a tough test (completely different hardware and software version). Unfortunately, I can't get my hands on another device running 4.1.1 and/or another Samsung Galaxy Note 2 running a different version.
I tried it on another device Samsung Galaxy S2 and it fires success only once so it may be specific to Note 2 device. I don't have a Note 2 device at hand but I will see if I can arrange one.
Ok, I downloaded the titanium_mobile source and compiled it for android with some added debugging statements in the takePicture functions. Here's a shortened version of the results (with debug enabled for Android): What I did: 1. Opened the app 2. Opened the camera in the app 3. Cleared the log 4. Took a single picture *On Samsung Galaxy Note 2 running Android 4.1.1* Short Version:
Longer Version:
*On HTC EVO 4G running Android 2.3.5* Short Version:
Longer Version:
--- After seeing that... it does look like the AutoFocus callback is being fired 3 times for some reason on the Samsung Galaxy Note 2. I'm going to look into it a bit more and see if I can figure out why that may be, but if anyone has any thoughts any help would be much appreciated.
This behavior clearly appeared after the integration of the SDK 3.2.1.GA (we were using 3.1.3.GA before). Some of our app users said that "when taking a picture, the camera takes a bunch of pics simultaneously (kind of like a burst)". It is clearly device specific. No issue on the HTC One for example. I reproduced this behavior on Samsung Galaxy S4 devices - I guess that some specific Samsung devices are affected - This is a regression of the SDK 3.2.X devices that crash: - Samsung Galaxy S4 (GT-9505) - Android version: 4.3 - Samsung Galaxy S4 (GT-9505) - Android version: 4.3.1 (CyanogenMod) I tried on other Samsung devices but I did not reproduce this behavior: - Samsung Galaxy S3 (GT-I9300) - Android version: 4.3 - Samsung Galaxy S2 (GT-I9100P) - Android version: 4.0.3 - Samsung Galaxy Note (GT-N7000) - Android version: 4.1.2 We also noticed crash reports about the camera of our app on Google Play Developer Console. They are clearly introduced by this new SDK... We were very confident about camera improvements using this new SDK, but it brought a lot of crashes (we are using the overlay option) so we urgently published a new app using the old SDK (3.1.3.GA). It is hard to create Jiras for these crashes because we did not reproduce on our devices.
Here is the simple test app I used (very similar to Mike's one):
Is there something new about this issue? Without fix, we cannot upgrade our Titanium SDK. And that makes us very sad :(
Hieu, thoughts?
The issue is reproducible with SDK version 3.2.2.GA & it is a regression as the user states they see after they updated from 3.1.3.GA. I used the code mentioned in the description above to reproduce it. This might be device specific according to comments above. My observations are as follows(with the devices we have):
With 3.2.2.GA:
1. Reproducible on Samsung Galaxy S3(SGH-I747) - android 4.0.4 : I get continuous triggers of success after taking the pic. 2. Not Reproducible on Samsung Galaxy S4 (SGH-I337) - android 4.2.2 : I get one success as expected. 3. Not Reproducible on Nexus 5 - android 4.4.2 : I get one success as expected. 4. Not Reproducible on Samsung Note 2 (SCH I-605) - android 4.3 : I get one success as expected. 5. Not Reproducible on Sony Experia - android 2.3.7 : I get one success as expected.With 3.2.3.v20140415094118:
1. Reproducible on Samsung Galaxy S3(SGH-I747) - android 4.0.4 : I get continuous triggers of success after taking the pic. 2. Reproducible on Samsung Galaxy S4 (SGH-I337) - android 4.2.2 : I get continuous triggers of success after taking the pic. 3. Not Reproducible on Nexus 5 - android 4.4.2 : I get one success as expected. 4. Not Reproducible on Samsung Note 2 (SCH I-605) - android 4.3 : I get one success as expected. 5. Not Reproducible on Sony Experia - android 2.3.7 : I get one success as expected.PR: https://github.com/appcelerator/titanium_mobile/pull/5887
3_3_X PR: https://github.com/appcelerator/titanium_mobile/pull/5937
Verified fix on: Mac OSX 10.9.4 Appcelerator Studio, build: 3.4.0.201408051600 Titanium SDK build: 3.4.0.v20140815142514 Titanium CLI, build: 3.4.0-dev Alloy: 1.6.0-dev Android Device S3 (4.0.4) Android Device Nexus (4.2.2) Android Device S4 (4.4.2) Tested using the devices/OS version that Lokesh was able to reproduce the bugs on and the code in the description. After taking a picture the success function is fired only once on each device. Below is the output from the S4
S4 Output
Closing ticket.