gpt4 book ai didi

javascript - Phonegap 相机错误

转载 作者:行者123 更新时间:2023-11-29 21:34:31 24 4
gpt4 key购买 nike

我目前只想拍摄一张照片,并在相机关闭后立即将图片添加为 HTML 图像的来源。但我不断收到以下错误:

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

现在我使用的是 Android 4.0.3 和 Cordova 2.3.0。我目前有以下代码:

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

我真的不确定为什么会收到此错误。非常感谢任何帮助。

在我的 config.xml 文件中,我拥有以下权限:

<plugin name="Camera" value="org.apache.cordova.CameraLauncher"/>

在我的 android list 中我有:

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

最佳答案

尝试使用以下代码。我猜您没有使用 PhoneGap 事件监听器调用 onDeviceReady 函数。

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

关于javascript - Phonegap 相机错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18703960/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com