检索数据时 Phonegap 摄像头故障
------------- 更新 --------------
HTC Desire 似乎存在某种问题相机和此版本的 Phonegap。问题似乎出在 HTC 在 Android 上返回相机规格的方式。
-------------- 更新 ---------------
我一直在使用phonegap 重写我的代码以前的应用程序,但不是我需要使用相机 API。当我在真实手机上使用它时,它在拍照后崩溃,并且我在 SendLog 中收到此错误。
10-07 09:44:46.980 D/AndroidRuntime( 1626): Shutting down VM
10-07 09:44:46.980 W/dalvikvm( 1626): threadid=1: thread exiting with uncaught exception (group=0x400259f8)
10-07 09:44:46.989 W/CameraThread( 1159): Release Camera - set mIsLastCameraClosed to true
10-07 09:44:46.989 W/CameraThread( 1159): CameraHandler Message - CLOSE_CAMERA end
10-07 09:44:46.989 E/AndroidRuntime( 1626): FATAL EXCEPTION: main
10-07 09:44:46.989 E/AndroidRuntime( 1626): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=33, result=-1, data=Intent { act=inline-data (has extras) }} to activity {com.theinit.example/com.theinit.example.TestPhoneGapActivity}: java.lang.NullPointerException
10-07 09:44:46.989 E/AndroidRuntime( 1626): at android.app.ActivityThread.deliverResults(ActivityThread.java:3734)
10-07 09:44:46.989 E/AndroidRuntime( 1626): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3776)
10-07 09:44:46.989 E/AndroidRuntime( 1626): at android.app.ActivityThread.access$2800(ActivityThread.java:135)
10-07 09:44:46.989 E/AndroidRuntime( 1626): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2166)
10-07 09:44:46.989 E/AndroidRuntime( 1626): at android.os.Handler.dispatchMessage(Handler.java:99)
10-07 09:44:46.989 E/AndroidRuntime( 1626): at android.os.Looper.loop(Looper.java:144)
10-07 09:44:46.989 E/AndroidRuntime( 1626): at android.app.ActivityThread.main(ActivityThread.java:4937)
10-07 09:44:46.989 E/AndroidRuntime( 1626): at java.lang.reflect.Method.invokeNative(Native Method)
10-07 09:44:46.989 E/AndroidRuntime( 1626): at java.lang.reflect.Method.invoke(Method.java:521)
10-07 09:44:46.989 E/AndroidRuntime( 1626): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-07 09:44:46.989 E/AndroidRuntime( 1626): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
10-07 09:44:46.989 E/AndroidRuntime( 1626): at dalvik.system.NativeStart.main(Native Method)
10-07 09:44:46.989 E/AndroidRuntime( 1626): Caused by: java.lang.NullPointerException
10-07 09:44:46.989 E/AndroidRuntime( 1626): at android.content.ContentResolver.openInputStream(ContentResolver.java:286)
10-07 09:44:46.989 E/AndroidRuntime( 1626): at com.phonegap.CameraLauncher.onActivityResult(CameraLauncher.java:248)
10-07 09:44:46.989 E/AndroidRuntime( 1626): at com.phonegap.DroidGap.onActivityResult(DroidGap.java:1346)
10-07 09:44:46.989 E/AndroidRuntime( 1626): at android.app.Activity.dispatchActivityResult(Activity.java:3931)
10-07 09:44:46.989 E/AndroidRuntime( 1626): at android.app.ActivityThread.deliverResults(ActivityThread.java:3730)
10-07 09:44:46.989 E/AndroidRuntime( 1626): ... 11 more
有谁知道为什么会发生这种情况?
这是我的 Camera.js
这是我的 Camera.js
var options = { quality : 75,
destinationType : Camera.DestinationType.DATA_URL,
sourceType : Camera.PictureSourceType.CAMERA,
allowEdit : true,
targetWidth: 100,
targetHeight: 100 };
function capturePhoto() {
// Take picture using device camera and retrieve image as base64-encoded string
navigator.camera.getPicture(onPhotoDataSuccess, onFail, options);
}
function onPhotoDataSuccess() {
// Uncomment to view the base64 encoded image data
var theHTML = '';
theHTML = '<div id="info">CameraSuccess</div>';
document.getElementById('main').innerHTML = theHTML;
}
function onFail(message) {
// Called if something bad happens.
alert('Failed because: ' + message);
}
希望它有帮助
谢谢大家
--------------- UPDATE ---------------
Seems that there´s some kind of problem with HTC Desire camera and this version of Phonegap. The issue seems to be the way HTC returns the camera specs on Android.
--------------- UPDATE ---------------
I´ve been using phonegap to rewrite the code of my previous application but not I need to use the camera API. When I used it on a real phone it crashed after taking the photo and i got this error with SendLog.
10-07 09:44:46.980 D/AndroidRuntime( 1626): Shutting down VM
10-07 09:44:46.980 W/dalvikvm( 1626): threadid=1: thread exiting with uncaught exception (group=0x400259f8)
10-07 09:44:46.989 W/CameraThread( 1159): Release Camera - set mIsLastCameraClosed to true
10-07 09:44:46.989 W/CameraThread( 1159): CameraHandler Message - CLOSE_CAMERA end
10-07 09:44:46.989 E/AndroidRuntime( 1626): FATAL EXCEPTION: main
10-07 09:44:46.989 E/AndroidRuntime( 1626): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=33, result=-1, data=Intent { act=inline-data (has extras) }} to activity {com.theinit.example/com.theinit.example.TestPhoneGapActivity}: java.lang.NullPointerException
10-07 09:44:46.989 E/AndroidRuntime( 1626): at android.app.ActivityThread.deliverResults(ActivityThread.java:3734)
10-07 09:44:46.989 E/AndroidRuntime( 1626): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3776)
10-07 09:44:46.989 E/AndroidRuntime( 1626): at android.app.ActivityThread.access$2800(ActivityThread.java:135)
10-07 09:44:46.989 E/AndroidRuntime( 1626): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2166)
10-07 09:44:46.989 E/AndroidRuntime( 1626): at android.os.Handler.dispatchMessage(Handler.java:99)
10-07 09:44:46.989 E/AndroidRuntime( 1626): at android.os.Looper.loop(Looper.java:144)
10-07 09:44:46.989 E/AndroidRuntime( 1626): at android.app.ActivityThread.main(ActivityThread.java:4937)
10-07 09:44:46.989 E/AndroidRuntime( 1626): at java.lang.reflect.Method.invokeNative(Native Method)
10-07 09:44:46.989 E/AndroidRuntime( 1626): at java.lang.reflect.Method.invoke(Method.java:521)
10-07 09:44:46.989 E/AndroidRuntime( 1626): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
10-07 09:44:46.989 E/AndroidRuntime( 1626): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
10-07 09:44:46.989 E/AndroidRuntime( 1626): at dalvik.system.NativeStart.main(Native Method)
10-07 09:44:46.989 E/AndroidRuntime( 1626): Caused by: java.lang.NullPointerException
10-07 09:44:46.989 E/AndroidRuntime( 1626): at android.content.ContentResolver.openInputStream(ContentResolver.java:286)
10-07 09:44:46.989 E/AndroidRuntime( 1626): at com.phonegap.CameraLauncher.onActivityResult(CameraLauncher.java:248)
10-07 09:44:46.989 E/AndroidRuntime( 1626): at com.phonegap.DroidGap.onActivityResult(DroidGap.java:1346)
10-07 09:44:46.989 E/AndroidRuntime( 1626): at android.app.Activity.dispatchActivityResult(Activity.java:3931)
10-07 09:44:46.989 E/AndroidRuntime( 1626): at android.app.ActivityThread.deliverResults(ActivityThread.java:3730)
10-07 09:44:46.989 E/AndroidRuntime( 1626): ... 11 more
Does anyone know why this happens?
This is my Camera.js
This is my Camera.js
var options = { quality : 75,
destinationType : Camera.DestinationType.DATA_URL,
sourceType : Camera.PictureSourceType.CAMERA,
allowEdit : true,
targetWidth: 100,
targetHeight: 100 };
function capturePhoto() {
// Take picture using device camera and retrieve image as base64-encoded string
navigator.camera.getPicture(onPhotoDataSuccess, onFail, options);
}
function onPhotoDataSuccess() {
// Uncomment to view the base64 encoded image data
var theHTML = '';
theHTML = '<div id="info">CameraSuccess</div>';
document.getElementById('main').innerHTML = theHTML;
}
function onFail(message) {
// Called if something bad happens.
alert('Failed because: ' + message);
}
Hope it helps
Thanks all by the way
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
-------------- 更新 ---------------
------------- 更新 ---------------
这段代码对我来说效果很好,我只有索引上此代码的 .js 引用以及带有 capturePhoto() 函数的按钮。
希望它可以帮助任何人解决他们的问题。
--------------- UPDATE ---------------
--------------- UPDATE ---------------
This code works fine for me, I've got only the .js reference to this code on the index and a button with the capturePhoto() function.
Hope it helps to anyone fix their problems.
编辑
最初我以为清除手机上的应用程序并重新安装就可以解决问题。事实证明事实并非如此。我发现存在一个问题:当尝试从相机抓取图像时,PhoneGap 应用程序会被 Android 垃圾收集删除。经过几个小时的搜索后,我最终找到的解决方案是使用前景相机插件。该插件在应用程序本身内部创建了自己的相机,这样您就不必担心垃圾收集会拾取它。
不幸的是,它的功能并不完整,并且大多数相机选项都不可供用户使用。它还仅支持 Cordova 2.4.0,这意味着我必须从 2.7.0 降级。该解决方案适用于我当前的应用程序,希望在我编写的下一个应用程序中会有更好的解决方案。希望这对某人有帮助!
EDIT
Originally I had thought that clearing my application on my phone and re-installing it had fixed the issue. It turns out this wasn't the case. I found out that there is an issue where the PhoneGap app is removed with the Android Garbage Collection when trying to grab an image from the camera. After searching for hours the solution I ended up going with was using the foreground camera plugin. This plugin creates its own camera inside of the application itself this way you don't have to worry about garbage collection picking it up.
Unfortunately, it's not fully featured and the most of the camera options aren't available to the user. It also only supports Cordova 2.4.0 which means I had to downgrade from 2.7.0. This solution will work for my current application, hopefully by the next one I write there will be a better solution. Hope this helps someone!
我刚刚在 PhoneGap 问题列表中帮助了一个遇到同样错误的人。我相信您缺少
AndroidManifest.xml 文件中的权限:。我们需要能够将捕获的图像写入 .jpg 文件。
I just helped a person with the same error on the PhoneGap issue list. I believe you are missing the permission:
from your AndroidManifest.xml file. We need to be able the write the captured image out to a .jpg file.
当我将 AndroidManifest.xml 中的 minSdkVersion 设置为 7 时,我遇到了同样的问题。当我使用 minSdkVersion="2" 时,我没有遇到此问题。
I had the same problem when I set my minSdkVersion within the AndroidManifest.xml to 7. I don't experience this problem when I use minSdkVersion="2".