Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-16199] Android: camera with overlay takePicture() firing success function multiple times

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2014-07-07T22:33:08.000+0000
Affected Version/sn/a
Fix Version/sRelease 3.4.0
Componentsn/a
Labelsandroid, camera, module_media, qe-manualtest, regression
ReporterMike Fogg
AssigneePing Wang
Created2014-01-09T19:25:51.000+0000
Updated2016-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]

Comments

  1. Ritu Agrawal 2014-01-12

    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.
  2. Mike Fogg 2014-01-13

    @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.
  3. Ritu Agrawal 2014-01-14

    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.
  4. Mike Fogg 2014-01-15

    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:
       showCamera called
       Camera :: Currently running with focusMode active.
       ...
       Camera :: Firing autofocus callback.
       Camera :: Firing shutterCallback.
       Camera :: Firing jpegCallback.
       Camera :: Firing successCallback.
       Camera :: Currently has autohide inactive.
       ...
       Camera :: Firing autofocus callback.
       Camera :: Firing shutterCallback.
       Camera :: Firing jpegCallback.
       Camera :: Firing successCallback.
       Camera :: Currently has autohide inactive.
       ...
       Camera :: Firing autofocus callback.
       Camera :: Firing shutterCallback.
       Camera :: Firing jpegCallback.
       Camera :: Firing successCallback.
       ...
       Unable to load bitmap. Not enough memory: null
       
    Longer Version:
       ...
       [DEBUG] :  TiMedia: (KrollRuntimeThread) [4,33606] showCamera called
       ...
       [DEBUG] :  TiBaseActivity: (main) [25,33662] Activity ti.modules.titanium.media.TiCameraActivity@4209dd58 onCreate
       [DEBUG] :  TiBaseActivity: (main) [9,33671] Activity ti.modules.titanium.media.TiCameraActivity@4209dd58 onStart
       [DEBUG] :  TiBaseActivity: (main) [9,33680] Activity ti.modules.titanium.media.TiCameraActivity@4209dd58 onResume
       ...
       [DEBUG] :  TiCameraActivity: (KrollRuntimeThread) [3,38699] Camera :: Currently running with focusMode active.
       ...
       [DEBUG] :  TiCameraActivity: (main) [20,38757] Camera :: Firing autofocus callback.
       ...
       [DEBUG] :  TiCameraActivity: (main) [22,38966] Camera :: Firing shutterCallback.
       [DEBUG] :  dalvikvm: GC_FOR_ALLOC freed 294K, 12% free 16691K/18887K, paused 19ms, total 19ms
       [INFO] :   I/dalvikvm-heap: Grow heap (frag case) to 18.781MB for 2149647-byte allocation
       [DEBUG] :  dalvikvm: GC_CONCURRENT freed <1K, 11% free 18790K/20999K, paused 11ms+1ms, total 26ms
       [DEBUG] :  dalvikvm: WAIT_FOR_CONCURRENT_GC blocked 7ms
       ...
       [DEBUG] :  TiCameraActivity: (main) [70,39036] Camera :: Firing jpegCallback.
       [DEBUG] :  TiCameraActivity: (main) [0,39036] Camera :: Firing successCallback.
       [DEBUG] :  TiCameraActivity: (main) [5,39041] Camera :: Currently has autohide inactive.
       [DEBUG] :  TiCameraActivity: (main) [0,39041] Camera :: Firing autofocus callback.
       ...
       [DEBUG] :  TiCameraActivity: (main) [4,39153] Camera :: Firing shutterCallback.
       ...
       [DEBUG] :  TiUIView: (main) [7,39182] starting animation
       [DEBUG] :  TiAnimationBuilder: (main) [0,39182] Property Animations will be used.
       [DEBUG] :  dalvikvm: GC_CONCURRENT freed 24K, 6% free 34453K/36615K, paused 12ms+6ms, total 61ms
       [DEBUG] :  dalvikvm: WAIT_FOR_CONCURRENT_GC blocked 15ms
       [DEBUG] :  dalvikvm: GC_FOR_ALLOC freed 3K, 6% free 34450K/36615K, paused 12ms, total 12ms
       [INFO] :   I/dalvikvm-heap: Grow heap (frag case) to 35.833MB for 1845622-byte allocation
       [DEBUG] :  dalvikvm: GC_FOR_ALLOC freed 2K, 6% free 36250K/38471K, paused 31ms, total 31ms
       ...
       [DEBUG] :  TiCameraActivity: (main) [0,39243] Camera :: Firing jpegCallback.
       [DEBUG] :  TiCameraActivity: (main) [0,39243] Camera :: Firing successCallback.
       [DEBUG] :  TiCameraActivity: (main) [1,39244] Camera :: Currently has autohide inactive.
       ...
       [DEBUG] :  dalvikvm: GC_FOR_ALLOC freed 62K, 6% free 36291K/38471K, paused 16ms, total 16ms
       [INFO] :   I/dalvikvm-heap: Grow heap (frag case) to 51.112MB for 15980560-byte allocation
       [DEBUG] :  dalvikvm: GC_FOR_ALLOC freed 1K, 5% free 51895K/54087K, paused 29ms, total 29ms
       ...
       [DEBUG] :  TiCameraActivity: (main) [1,39528] Camera :: Firing autofocus callback.
       ...
       [DEBUG] :  TiCameraActivity: (main) [3,39892] Camera :: Firing shutterCallback.
       [DEBUG] :  TiCameraActivity: (main) [0,39892] Camera :: Firing jpegCallback.
       [DEBUG] :  TiCameraActivity: (main) [1,39893] Camera :: Firing successCallback.
       ...
       [DEBUG] :  dalvikvm: GC_FOR_ALLOC freed 86K, 4% free 53984K/56199K, paused 15ms, total 15ms
       [INFO] :   I/dalvikvm-heap: Forcing collection of SoftReferences for 15980560-byte allocation
       [DEBUG] :  dalvikvm: GC_BEFORE_OOM freed 9K, 4% free 53974K/56199K, paused 37ms, total 37ms
       [ERROR] :  E/dalvikvm-heap: Out of memory on a 15980560-byte allocation.
       [INFO] :   dalvikvm: "pool-3-thread-1" prio=5 tid=12 RUNNABLE
       [INFO] :   dalvikvm:   | group="main" sCount=0 dsCount=0 obj=0x42138408 self=0x60414158
       [INFO] :   dalvikvm:   | sysTid=18254 nice=0 sched=0/0 cgrp=apps handle=1605730104
       [INFO] :   dalvikvm:   | schedstat=( 411321756 119970746 446 ) utm=37 stm=3 core=1
       [INFO] :   dalvikvm:   at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
       [INFO] :   dalvikvm:   at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:650)
       [INFO] :   dalvikvm:   at org.appcelerator.titanium.view.TiDrawableReference.getBitmap(TiDrawableReference.java:324)
       [INFO] :   dalvikvm:   at org.appcelerator.titanium.util.TiLoadImageManager$LoadImageJob.run(TiLoadImageManager.java:128)
       [INFO] :   dalvikvm:   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
       [INFO] :   dalvikvm:   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
       [INFO] :   dalvikvm:   at java.lang.Thread.run(Thread.java:856)
       [INFO] :   dalvikvm:
       [DEBUG] :  skia: --- decoder->decode returned false
       [ERROR] :  TiDrawableReference: (pool-3-thread-1) [54,40012] Unable to load bitmap. Not enough memory: null
       [ERROR] :  TiDrawableReference: java.lang.OutOfMemoryError
       [ERROR] :  TiDrawableReference:   at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
       [ERROR] :  TiDrawableReference:   at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:650)
       [ERROR] :  TiDrawableReference:   at org.appcelerator.titanium.view.TiDrawableReference.getBitmap(TiDrawableReference.java:324)
       [ERROR] :  TiDrawableReference:   at org.appcelerator.titanium.util.TiLoadImageManager$LoadImageJob.run(TiLoadImageManager.java:128)
       [ERROR] :  TiDrawableReference:   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
       [ERROR] :  TiDrawableReference:   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
       [ERROR] :  TiDrawableReference:   at java.lang.Thread.run(Thread.java:856)
       
    *On HTC EVO 4G running Android 2.3.5* Short Version:
       showCamera called
       Camera :: Currently running with focusMode active.
       ...
       Camera :: Firing autofocus callback.
       Camera :: Firing shutterCallback.
       Camera :: Firing jpegCallback.
       Camera :: Firing successCallback.
       Camera :: Currently has autohide inactive.
       
    Longer Version:
       ...
       [DEBUG] :  TiMedia: (KrollRuntimeThread) [101,79171] showCamera called
       ...
       [DEBUG] :  TiBaseActivity: (main) [26,79232] Activity ti.modules.titanium.media.TiCameraActivity@40627d28 onCreate
       [DEBUG] :  TiBaseActivity: (main) [9,79241] Activity ti.modules.titanium.media.TiCameraActivity@40627d28 onStart
       [DEBUG] :  TiBaseActivity: (main) [1,79242] Activity ti.modules.titanium.media.TiCameraActivity@40627d28 onResume
       ...
       [DEBUG] :  TiCameraActivity: (KrollRuntimeThread) [40,83149] Camera :: Currently running with focusMode active.
       ...
       [DEBUG] :  TiCameraActivity: (main) [377,83785] Camera :: Firing autofocus callback.
       [DEBUG] :  TiCameraActivity: (main) [266,84051] Camera :: Firing shutterCallback.
       ...
       [DEBUG] :  dalvikvm: GC_FOR_MALLOC freed 1138K, 30% free 7971K/11335K, external 15690K/17724K, paused 34ms
       [INFO] :   I/dalvikvm-heap: Grow heap (frag case) to 28.419MB for 3392203-byte allocation
       [DEBUG] :  dalvikvm: GC_CONCURRENT freed 1K, 24% free 11282K/14663K, external 15690K/17724K, paused 3ms+3ms
       ...
       [DEBUG] :  TiCameraActivity: (main) [1023,85074] Camera :: Firing jpegCallback.
       [DEBUG] :  TiCameraActivity: (main) [40,85114] Camera :: Firing successCallback.
       [DEBUG] :  TiCameraActivity: (main) [2,85116] Camera :: Currently has autohide inactive.
       
    --- 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.
  5. Arnaud Besnier 2014-03-11

    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.
  6. Arnaud Besnier 2014-03-11

    Here is the simple test app I used (very similar to Mike's one):
       // Window to open the camera ---------------------------------------------------
       
       var snapshotCount = 0;
       
       var win = Ti.UI.createWindow({
       	backgroundColor: 'white',
       	navBarHidden:    true,
       	exitOnClose:     true
       });
       
       var view = Ti.UI.createView();
       win.add(view);
       
       var button = Ti.UI.createButton({
       	title:  'OpenCamera',
       	height: 'auto',
       	width:  'auto'
       });
       view.add(button);
       
       // Camera overlay --------------------------------------------------------------
       
       var overlayView = Ti.UI.createView({});
       
       var snapshotButton = Ti.UI.createButton({
       	title:  'Take Snapshot',
       	bottom: '10dp'
       });
       overlayView.add(snapshotButton);
       
       function takePicture() {
       	snapshotCount = 0;
       	Ti.Media.takePicture();
       }
       
       snapshotButton.addEventListener('click', takePicture);
       
       // Camera opening --------------------------------------------------------------
       
       button.addEventListener('click', function(e) {
       	Ti.Media.showCamera({
       		success: function(){
       			snapshotCount += 1;
       			alert('Snapshot ' + snapshotCount + ' done');
       		},
       		cancel: function(){},
       		error:  function(){},
       		transform:          false,
       		mediaTypes:         Ti.Media.MEDIA_TYPE_PHOTO,
       		overlay:            overlayView,
       		showControls:       false,
       		saveToPhotoGallery: false,
       		autohide:           false
       	});
       });
       
       win.open();
       
  7. Arnaud Besnier 2014-04-16

    Is there something new about this issue? Without fix, we cannot upgrade our Titanium SDK. And that makes us very sad :(
  8. Ingo Muschenetz 2014-04-16

    Hieu, thoughts?
  9. Lokesh Choudhary 2014-04-16

    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.
  10. Ping Wang 2014-07-03

    PR: https://github.com/appcelerator/titanium_mobile/pull/5887
  11. Ping Wang 2014-07-25

    3_3_X PR: https://github.com/appcelerator/titanium_mobile/pull/5937
  12. Ewan Harris 2014-08-19

    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

        [INFO] :   ALERT: (KrollRuntimeThread) [6810,10213] opening
        [INFO] :   ALERT: (KrollRuntimeThread) [3881,14094] success
        
    Closing ticket.
  13. Mike Fogg 2016-08-12

JSON Source