2
votes

I am having a problem when capturing a photo in Cordova / Phonegap 3.2 app on Android devices.

When I run the navigator.camera.getPicture function, the camera returns success after around 30 seconds, sometimes longer. However, when I tap the camera button again (running the navigator.camera.getPicture function again, without capturing the shot), it immedietyl return the control back to the app and resumes the process of the app.

It looks that like the app it stuck after I capture an image (although I do return to the app after the camera finished capturing the photo), and the only things that cause the camera to continue its operation and get into the success function is by running the getPicture function again.

This doesn't happen on iOS7, and I experience it only on Android (tried with Android versions 2.3.5, 4.1.2).

I put an alert before the navigator.camera.getPicture call and it runs ok. I also put an alert in the success function and it doesn't run. So I assume that something else in the capture plugin causes the delay.

I've checked the CPU and it is low. I disabled any other background process and webservice calls to make sure that it doesn't cause this behavior.

I also used a very small image size to make sure that the the large size of the image doesn't cause this problem. So I also eliminated the image size factor.

The getPicture function:

 navigator.camera.getPicture(function () {   
        // On get photo success

        that._onPhotoURISuccess.apply(that, arguments);
         return false;
    }, function (err) {


    }, {
        quality: CAPTURED_PHOTO_IMAGE_QUALITY,
        destinationType: Camera.DestinationType.FILE_URI, 
        encodingType: Camera.EncodingType.JPEG,
        saveToPhotoAlbum: SETTINGS_SAVE_TO_PHOTO_ALBUM,
        allowEdit: false,
        sourceType: Camera.PictureSourceType.CAMERA, 
        targetWidth: maxSize, // <= 1024
        targetHeight: maxSize, 
        correctOrientation: true,  
    });

LOG For Behavior 1:

After the image is saved:

03-27 21:11:10.812: V/webview(11988):  singleCursorHandlerTouchEvent -getEditableSupport  FASLE 
03-27 21:11:11.281: D/CordovaActivity(11988): Paused the application!
03-27 21:11:11.281: D/CordovaWebView(11988): Handle the pause
03-27 21:11:11.296: W/PluginManager(11988): THREAD WARNING: exec() call to Camera.takePicture blocked the main thread for 33ms. Plugin should use CordovaInterface.getThreadPool().
03-27 21:11:11.382: W/PluginManager(11988): THREAD WARNING: exec() call to WebSocket.send blocked the main thread for 18ms. Plugin should use CordovaInterface.getThreadPool().
03-27 21:11:12.117: W/IInputConnectionWrapper(11988): showStatusIcon on inactive InputConnection
03-27 21:11:17.070: D/CordovaActivity(11988): Incoming Result
03-27 21:11:17.070: D/CordovaActivity(11988): Request code = 34
03-27 21:11:17.070: D/CordovaActivity(11988): We have a callback to send this result to
03-27 21:11:17.585: D/dalvikvm(11988): GC_EXTERNAL_ALLOC freed 563K, 52% free 4167K/8519K, external 5208K/5208K, paused 85ms
03-27 21:11:18.734: D/dalvikvm(11988): GC_EXPLICIT freed 19K, 52% free 4161K/8519K, external 8280K/8422K, paused 64ms
03-27 21:11:18.750: D/Whitelist(11988): Unlimited access to network resources
03-27 21:11:18.757: I/CordovaLog(11988): Found start page location: index.html
03-27 21:11:18.757: D/Config(11988): The <log> tags is deprecated. Use <preference name="loglevel" value="DEBUG"/> instead.
03-27 21:11:18.757: I/CordovaLog(11988): Changing log level to DEBUG(3)
03-27 21:11:18.757: D/CordovaActivity(11988): Resuming the App
03-27 21:11:18.757: D/CordovaActivity(11988): CB-3064: The errorUrl is null
03-27 21:11:18.789: V/webview(11988): OnSizeChanged: Enter 
03-27 21:11:18.804: D/SoftKeyboardDetect(11988): Ignore this event
03-27 21:11:19.125: V/webview(11988): OnSizeChanged: Enter 

Two minutes after, I've decided to click the camera button again:

03-27 21:13:07.539: D/dalvikvm(11988): GC_CONCURRENT freed 2057K, 52% free 4189K/8647K, external 408K/5208K, paused 4ms+5ms
03-27 21:13:37.539: D/dalvikvm(11988): GC_CONCURRENT freed 574K, 52% free 4177K/8647K, external 408K/5208K, paused 4ms+4ms
03-27 21:13:57.515: V/webview(11988):  singleCursorHandlerTouchEvent -getEditableSupport  FASLE 
03-27 21:13:57.984: D/CordovaActivity(11988): Paused the application!
03-27 21:13:57.984: D/CordovaWebView(11988): Handle the pause
03-27 21:13:58.000: W/PluginManager(11988): THREAD WARNING: exec() call to Camera.takePicture blocked the main thread for 33ms. Plugin should use CordovaInterface.getThreadPool().
03-27 21:13:58.351: D/FileTransfer(11988): upload file:///mnt/sdcard/Android/data/com.test.test/cache/1395947477121.jpg to http://test.test.com/service.asmx/SaveImage
03-27 21:13:58.351: D/FileTransfer(11988): fileKey: file
03-27 21:13:58.351: D/FileTransfer(11988): fileName: 26346703-41cc-452c-8e86-aac088c99781.jpg
03-27 21:13:58.351: D/FileTransfer(11988): mimeType: image/jpeg
03-27 21:13:58.359: D/FileTransfer(11988): params: {}
03-27 21:13:58.359: D/FileTransfer(11988): trustEveryone: false
03-27 21:13:58.367: D/FileTransfer(11988): chunkedMode: false
03-27 21:13:58.367: D/FileTransfer(11988): headers: {"Connection":"close"}
03-27 21:13:58.367: D/FileTransfer(11988): objectId: 4
03-27 21:13:58.398: D/FileTransfer(11988): httpMethod: POST
03-27 21:13:58.398: W/PluginManager(11988): THREAD WARNING: exec() call to FileTransfer.upload blocked the main thread for 96ms. Plugin should use CordovaInterface.getThreadPool().
03-27 21:13:58.398: D/FileTransfer(11988): Content Length: 28412
03-27 21:13:58.625: D/dalvikvm(11988): GC_CONCURRENT freed 453K, 51% free 4312K/8647K, external 408K/5208K, paused 4ms+5ms
03-27 21:13:58.914: D/FileTransfer(11988): Sent 28412 of 28412
03-27 21:13:59.156: W/IInputConnectionWrapper(11988): showStatusIcon on inactive InputConnection
03-27 21:13:59.257: D/FileTransfer(11988): response code: 200
03-27 21:13:59.281: D/FileTransfer(11988): response headers: {null=[HTTP/1.1 200 OK], Access-Control-Allow-Headers=[Content-Type], Access-Control-Allow-Origin=[*], Cache-Control=[private, max-age=0], Connection=[Close], Content-Length=[0], Date=[Thu, 27 Mar 2014 19:14:50 GMT], Server=[Microsoft-IIS/8.0], X-Android-Received-Millis=[1395947639258], X-Android-Response-Source=[NETWORK 200], X-Android-Sent-Millis=[1395947638596], X-AspNet-Version=[4.0.30319], X-Powered-By=[ASP.NET]}
03-27 21:13:59.281: D/FileTransfer(11988): got response from server
03-27 21:14:00.796: D/CordovaActivity(11988): Incoming Result
03-27 21:14:00.796: D/CordovaActivity(11988): Request code = 34
03-27 21:14:00.796: D/CordovaActivity(11988): We have a callback to send this result to
03-27 21:14:00.835: D/Whitelist(11988): Unlimited access to network resources
03-27 21:14:00.843: I/CordovaLog(11988): Found start page location: index.html
03-27 21:14:00.843: D/Config(11988): The <log> tags is deprecated. Use <preference name="loglevel" value="DEBUG"/> instead.
03-27 21:14:00.976: I/CordovaLog(11988): Changing log level to DEBUG(3)
03-27 21:14:00.976: D/CordovaActivity(11988): Resuming the App
03-27 21:14:00.976: D/CordovaActivity(11988): CB-3064: The errorUrl is null
03-27 21:14:01.070: V/webview(11988): OnSizeChanged: Enter 
03-27 21:14:01.078: D/SoftKeyboardDetect(11988): Ignore this event
03-27 21:14:01.289: V/webview(11988): OnSizeChanged: Enter 
03-27 21:14:01.609: D/skia(11988): purging 197K from font cache [29 entries]

Update 2: Another thing that I've noticed. When I put an alert on the error callback for the getPicture function, I get "Cameera cancelled" error. Although when I launch the camera again, the success callback is called.

Update 3: another person who experienced the same issue

The three behaviors that I encounter in more details:

Behavior 1:

  1. I click the camera capture button
  2. Clicked to save the photo in camera preview window
  3. Nothing happens, the success nor the fail callback are called (waited for 2 minutes)
  4. I click the camera button again, the success callback is called, I click the back button the camera preview window
  5. I can see the image in the view
  6. Get the fail callback from the second time I pressed the camera button (I assume that it's from the second one)

Behavior 2:

  1. I click the camera capture button
  2. After 5-30 seconds the success callback is called
  3. CPU is at 100% (uploading the image)
  4. Upload success function called

Behavior 3:

  1. I click the camera capture button
  2. I cancel the capture and go back to the app
  3. Calls the fail callback after approx. 15 seconds
  4. If I click the camera button right after step 2, I get the fail callback immediately

Those are the main issues. The common for those three are long delays and immediate continuation of the callback function when I interrupt the delay with a second camera getPicture call (pressing the camera button).

The issues are not consistent. In rare situations It does work as intended without delays, but most of the time I encounter those issues. The issues can happen right after I launch the app or after some time, and there is no way to debug them because the delay happens in the camera plugin itself, not in my code.

1
could you please include the code you use to call getPicture? And, have you tried with cordova 3.3 / 3.4?Paolo Casciello
Hi, Updated with the code. I can't use Cordova other then 3.2 due to limitations in ApplicationBuilder environment. I am using the latest version of the File, FileTransfer, Media Capture and Camera plugins though.Idan Shechter
You've tested with targetsize, have you also tried with different (small) quality values? I use it in on of our app and on android is slow to start the first time but at around 2-3 seconds on average phones.. :/Paolo Casciello
I tried with 10px sized images and with 10 quality, same issue. this guy had the same exact issue: groups.google.com/forum/#!topic/phonegap/7nmRrQoO8zUIdan Shechter
@PaoloCasciello I've updated the question with relevant debug tracing and more detailed info.Idan Shechter

1 Answers

0
votes

I faced the same problem on phonegap 2.9.0 , after doing many failed trials to solve the problem, I did the following

  • I created a new phonegap 3.5.0 project

  • I built the android platform from CLI

  • I copied the www folder to the new project root folder

  • I added all needed plugins using CLI

  • I did the necessary changes in top-level config.xml file for icon and splash screen because file construction is different

  • I ran the project , and it is ok now.