2016-03-16 20 views
0

我想上傳圖片。以前,它一切正常。突然間現在它停止在Android上工作。在iOS上測試相同的代碼,工作正常。應用程序崩潰,從畫廊 - 鈦的Android

使用案例: 點擊一個按鈕 - 打開相機(或可從庫中選擇) 2.捕獲的圖像 3.按「確定」按鈕 - 應用程序崩潰

我清理大量內存認爲有些設備可能有內存問題。根據新的發行說明添加攝像頭權限,仍然面臨問題。這裏是我的代碼:

var dialog = Ti.UI.createOptionDialog({ 
    options : ['Camera', 'Gallery', 'Cancel'], 
    title : 'Upload image using?' 
}); 

dialog.show(); 

dialog.addEventListener('click', function(e) { 

    if (e.index === 0) { 

     //Open Camera 
     Ti.Media.showCamera({ 
      saveToPhotoGallery : true, 

      success : function(event) { 
       console.error('UPLOAD IMAGE SUCCESS ', JSON.stringify(event)); 
       callback(event.media); 
      }, 

      cancel : function(err) { 
       console.error('UPLOAD IMAGE CANCEL ', JSON.stringify(err)); 
      }, 

      error : function(err) { 
       console.error('UPLOAD IMAGE ERROR ', JSON.stringify(err)); 
      }, 

      showControls : true, 
      mediaTypes : Ti.Media.MEDIA_TYPE_PHOTO, 
      autohide : true 
     }); 
    } else if (e.index === 1) { 

     //Open gallery 
     Ti.Media.openPhotoGallery({ 
      success : function(event) { 
       console.error('UPLOAD IMAGE SUCCESS ', JSON.stringify(event)); 
       callback(event.media); 
      }, 

      cancel : function(err) { 
       console.error('UPLOAD IMAGE CANCEL ', JSON.stringify(err)); 
      }, 

      error : function(err) { 
       console.error('UPLOAD IMAGE ERROR ', JSON.stringify(err)); 
      }, 
     }); 
    } else { 
     // Do nothing 
    } 
    dialog.hide(); 
}); 

tiapp.xml

<manifest> 
    <uses-permission android:name="android.permission.CAMERA" /> 
</manifest> 

誰能告訴什麼是錯的代碼或是否需要添加其他內容?

一些日誌:

[DEBUG] : skia: --- SkImageDecoder::Factory returned null 
[DEBUG] : skia: --- SkImageDecoder::Factory returned null 
[DEBUG] : skia: --- SkImageDecoder::Factory returned null 
[DEBUG] : skia: --- SkImageDecoder::Factory returned null 
[DEBUG] : skia: --- SkImageDecoder::Factory returned null 
[DEBUG] : Window: Window is closed normally. 
+0

logcat的請留言。 –

+0

您可以發佈您的logcat .. –

+0

而崩潰,我沒有得到任何調試日誌。 – Porwal

回答

0

爲了解決這個問題,我需要做的兩件事情。

  1. 在tiapp.xml添加此

    <manifest> <uses-permission android:name="android.permission.CAMERA" /> <uses-feature android:name="android.hardware.camera"/> </manifest>

  2. 打開設置>應用程序>照相

    • 強行關閉,然後清除數據和緩存
    • 重啓手機

這是我用來解決,並開始工作。

+0

之前,我相信這是與相機本身的問題。 – Porwal