2

我正在使用 PhoneGap (Cordova 1.6.1) 为 Android 开发一个应用程序。当我调用相机 API 时,我的应用程序崩溃并且我收到诸如“showStatusIcon on inactive InputConnection”之类的日志消息。我使用以下方法来调用相机:

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

2 回答 2

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>
于 2012-07-26T06:41:42.503 回答
0

在我的活动类的 onCreate 方法中,我设置了一个 Javascript 接口:

appView.addJavascriptInterface(this, "GC");

我创建了一种清理垃圾收集器的方法:

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

在我的 .js 文件中,我调用了之前的方法来调用相机或图片库:

GC.cleanGC();
于 2013-09-02T10:22:43.950 回答