Reputation: 3270
I'm currently looking to simply capture a photo and straight after the camera closes, add the picture as the source of an HTML image. But I keep getting the following error:
09-09 19:16:07.764: E/System(10719): Uncaught exception thrown by finalizer
09-09 19:16:07.780: D/dalvikvm(10719): GC_CONCURRENT freed <1K, 10% free 19133K/21127K, paused 1ms+2ms
09-09 19:16:07.788: E/System(10719): java.lang.IllegalStateException: Binder has been finalized!
09-09 19:16:07.788: E/System(10719): at android.os.BinderProxy.transact(Native Method)
09-09 19:16:07.788: E/System(10719): at android.database.BulkCursorProxy.close(BulkCursorNative.java:288)
09-09 19:16:07.788: E/System(10719): at android.database.BulkCursorToCursorAdaptor.close(BulkCursorToCursorAdaptor.java:133)
09-09 19:16:07.788: E/System(10719): at android.database.CursorWrapper.close(CursorWrapper.java:49)
09-09 19:16:07.788: E/System(10719): at android.content.ContentResolver$CursorWrapperInner.close(ContentResolver.java:1591)
09-09 19:16:07.788: E/System(10719): at android.content.ContentResolver$CursorWrapperInner.finalize(ContentResolver.java:1604)
09-09 19:16:07.788: E/System(10719): at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:182)
09-09 19:16:07.788: E/System(10719): at java.lang.Daemons$FinalizerDaemon.run(Daemons.java:168)
09-09 19:16:07.788: E/System(10719): at java.lang.Thread.run(Thread.java:856)
09-09 19:16:08.585: D/dalvikvm(10719): GC_EXPLICIT freed 12354K, 68% free 6804K/21127K, paused 2ms+3ms
09-09 19:16:08.585: E/System(10719): Uncaught exception thrown by finalizer
09-09 19:16:08.585: E/System(10719): java.lang.IllegalStateException: Binder has been finalized!
09-09 19:16:08.585: E/System(10719): at android.os.BinderProxy.transact(Native Method)
09-09 19:16:08.585: E/System(10719): at android.database.BulkCursorProxy.close(BulkCursorNative.java:288)
09-09 19:16:08.585: E/System(10719): at android.database.BulkCursorToCursorAdaptor.close(BulkCursorToCursorAdaptor.java:133)
09-09 19:16:08.585: E/System(10719): at android.database.CursorWrapper.close(CursorWrapper.java:49)
09-09 19:16:08.585: E/System(10719): at android.content.ContentResolver$CursorWrapperInner.close(ContentResolver.java:1591)
09-09 19:16:08.585: E/System(10719): at android.content.ContentResolver$CursorWrapperInner.finalize(ContentResolver.java:1604)
09-09 19:16:08.585: E/System(10719): at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:182)
09-09 19:16:08.585: E/System(10719): at java.lang.Daemons$FinalizerDaemon.run(Daemons.java:168)
09-09 19:16:08.585: E/System(10719): at java.lang.Thread.run(Thread.java:856)
09-09 19:16:08.585: D/DroidGap(10719): Resuming the App
Now I'm using Android 4.0.3 and Cordova 2.3.0. I currently have the following code:
HTML
<button onclick="capturePhoto();">Take Photo</button>
<img id="cameraPic" src="" style="width:auto;height:120px;"></img>
JavaScript
var pictureSource;
var destinationType;
function onDeviceReady() {
pictureSource=navigator.camera.PictureSourceType;
destinationType=navigator.camera.DestinationType;
}
function capturePhoto(){
navigator.camera.getPicture(uploadPhoto,null,{ quality: 20, allowEdit: true,
destinationType: destinationType.DATA_URL });
};
function uploadPhoto(data){
// this is where you would send the image file to server
//output image to screen
$("#cameraPic").src = "data:image/jpeg;base64," + data;
}
I'm really not to sure why I'm getting this error. Any help would really be appreciated.
In my config.xml file I have the following permissions:
<plugin name="Camera" value="org.apache.cordova.CameraLauncher"/>
And in my android manifest I have:
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Upvotes: 1
Views: 715
Reputation: 676
Try with the following code. I guess you are not calling the onDeviceReady function using PhoneGap event listener.
var pictureSource; // picture source
var destinationType; // sets the format of returned value
document.addEventListener("deviceready",onDeviceReady,false);
function onDeviceReady() {
pictureSource=navigator.camera.PictureSourceType;
destinationType=navigator.camera.DestinationType;
}
function capturePhoto() {
navigator.camera.getPicture(uploadPhoto, uploadFail, { quality: 20, allowEdit: true,
destinationType: destinationType.DATA_URL });
}
function uploadPhoto(data){
$("#cameraPic").src = "data:image/jpeg;base64," + data;
}
function uploadFail(error) {
alert('Failed because: ' + error);
}
Upvotes: 2
Reputation: 1736
Check the destination type.
navigator.camera.getPicture(onSuccess, onFail, { quality: 50,
destinationType: Camera.DestinationType.DATA_URL // check this line and replace it...
});
function onSuccess(imageData) {
var image = document.getElementById('myImage');
image.src = "data:image/jpeg;base64," + imageData;
}
function onFail(message) {
alert('Failed because: ' + message);
}
Upvotes: 0