2014-03-26 11 views
2

我在Android設備上的Cordova/Phonegap 3.2應用程序中捕獲照片時遇到問題。Phonegap getPicture函數長延遲,恢復召回

當我運行navigator.camera.getPicture功能時,相機在約30秒後返回成功,有時會更長。但是,當我再次點擊相機按鈕(再次運行navigator.camera.getPicture函數,而不捕獲鏡頭)時,它將immedietyl控制權返回給應用程序並恢復應用程序的進程。

它看起來像捕捉圖像後卡住的應用程序(雖然在相機完成拍攝照片後我會返回到應用程序),並且導致相機繼續操作並進入success function是通過再次運行getPicture函數。

這不會發生在iOS7上,我只在Android上體驗它(嘗試使用Android版本2.3.5,4.1.2)。

我在navigator.camera.getPicture調用之前發出了一個提醒,它運行正常。我也在成功函數中加入了一個警告,它不會運行。所以我認爲捕獲插件中的其他內容會導致延遲。

我檢查了CPU,它很低。我禁用了任何其他後臺進程和web服務調用,以確保它不會導致此行爲。

我還使用了一個非常小的圖像大小,以確保圖像的大尺寸不會導致此問題。所以我也消除了圖像尺寸因素。

的Getpicture中功能:

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, 
    }); 

日誌中行爲1:保存圖像

後:

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 

兩分鐘後,我已經決定要點擊相機按鈕:

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] 

更新2:另一件我注意到的事情。當我在getPicture函數的錯誤回調中發出警告時,我得到「Cameera取消」錯誤。雖然當我再次啓動相機時,成功回調被調用。

更新3:另一個人誰experienced the same issue

,我在更多的細節會遇到三種行爲:

行爲1:

  1. 我點擊相機拍攝按鈕
  2. 點擊將照片保存在相機預覽窗口中
  3. 沒有任何反應,成功還是失敗的回調被稱爲(等待2分鐘)
  4. 我再次點擊拍照鍵,成功回調被調用時,我點擊後退按鈕時,相機預覽窗口
  5. 我可以看到在觀看圖片
  6. 獲取從我第二次按下相機按鈕故障回調(我認爲它與第二個是)

行爲2:

  1. 我點擊相機拍攝按鈕
  2. 後5-30秒內成功回調被稱爲
  3. CPU爲100%(上傳圖片)叫

行爲

  • 上傳成功函數3:

    1. 我點擊相機拍攝按鈕
    2. 我取消捕獲並返回到應用程序
    3. 在約1秒鐘後調用失敗回調。 15秒
    4. 如果我點擊第2步之後的拍照鍵,我得到的失敗回調立即

    這些是主要問題。這三種情況的共同之處在於,當我用第二臺相機getPicture調用(按下相機按鈕)中斷延遲時,延遲時間很長,並立即延續了回調功能。

    問題不一致。在極少數情況下,它確實按預期工作,沒有延遲,但大多數時候我遇到這些問題。這些問題可能在我啓動應用程序後或一段時間後發生,並且無法調試它們,因爲延遲發生在相機插件本身中,而不是在我的代碼中。

  • +0

    請問您可以包含您用於調用getPicture的代碼嗎?而且,你是否嘗試過使用cordova 3.3/3.4? –

    +0

    嗨,更新了代碼。由於ApplicationBuilder環境的限制,我無法使用Cordova 3.2以上的版本。儘管我正在使用最新版本的File,FileTransfer,Media Capture和Camera插件。 –

    +0

    你已經用'targetsize'進行了測試,你是否還嘗試過不同(小)'質量'值?我在我們的應用程序中使用它,並在Android上第一次啓動緩慢,但在平均手機上大約2-3秒..:/ –

    回答

    0

    我面臨的PhoneGap的2.9.0同樣的問題,做很多試驗失敗來解決這個問題後,我做了以下

    • 我創建了一個新的PhoneGap 3.5。0項目

    • 我採用Android平臺,CLI

    • 我複製www文件夾到新項目的根文件夾

    • 我添加使用CLI

    • 所有插件需要我做的因爲文件結構不同,所以必須在頂級config.xml文件中更改圖標和啓動畫面

    • 我運行了該項目,現在好了。