2012-07-26 87 views
2

我正在使用PhoneGap(Cordova 1.6.1)開發Android應用程序。當我調用相機API時,我的應用程序崩潰,我收到諸如「在非活動InputConnection上的showStatusIcon」等日誌消息。我已經使用以下方法調用相機:Phonegap Camera應用程序崩潰

function capturePhoto() { 
     // Take picture using device camera and retrieve image as base64-encoded string 
     navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50, 
     destinationType: destinationType.DATA_URL }); 
    } 


function onPhotoDataSuccess(imageData) {   
     var smallImage = document.getElementById('smallImage'); 
     smallImage.style.display = 'block';  
    smallImage.src = "data:image/jpeg;base64," + imageData;  
    } 

function onFail(message) { 
    alert('Failed because: ' + message); 
} 

回答

1

我已經使用過它,它對我來說工作正常。請檢查 -

document.addEventListener("deviceready",onDeviceReady,false); 

function onDeviceReady() { 

console.log("CORDOVA IS WORKING:::"); 
} 

     function capturePhoto() 
{ 
navigator.camera.getPicture(onSuccess, onFail, { quality: 50, 
destinationType: Camera.DestinationType.FILE_URI }); 
} 

function onSuccess(imageURI) { 
var image = document.getElementById('myImage'); 
image.src = imageURI; 
} 

function onFail(message) { 
alert('Failed because: ' + message); 
}  
</script> 
0

在我的活動類的onCreate方法我設置了一個Javascript接口:

appView.addJavascriptInterface(this, "GC"); 

而且我已經創建了一個方法來清潔垃圾收集器:

public void cleanGC() { 
     System.gc(); 
    } 

在我的.js文件中,我調用之前的方法調用相機或pi cture圖庫:

GC.cleanGC();