检索数据时的PhoneGap相机故障 [英] Phonegap camera failure when retrieving data

查看:98
本文介绍了检索数据时的PhoneGap相机故障的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

---------------更新---------------

似乎there's某种与HTC Desire的摄像头的问题,这个版本的PhoneGap的。这个问题似乎是HTC返回Android上的摄像头规格的方式。

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.

---------------更新---------------

从来就一直在使用PhoneGap的重写我的previous应用程序的code,但不是我需要使用相机API。当我用它真正的手机上坠毁拍照后,我得到这个错误与SendLog。

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?

这是我的Camera.js

This is my Camera.js

这是我的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);
}

希望它能帮助

感谢所有的方式

推荐答案

---------------更新-------------- -

似乎there's某种与HTC Desire的摄像头的问题,这个版本的PhoneGap的。这个问题似乎是HTC返回Android上的摄像头规格的方式。

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.

---------------更新---------------

这code正常工作对我来说,我已经得到了只有.js文件提到关于该指数code和一个按钮与capturePhoto()函数。

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.

var pictureSource;   // picture source
var destinationType; // sets the format of returned value 

// Wait for PhoneGap to connect with the device
//
document.addEventListener("deviceready",onDeviceReady,false);

// PhoneGap is ready to be used!
//
function onDeviceReady() {
    pictureSource=navigator.camera.PictureSourceType;
    destinationType=navigator.camera.DestinationType;
}

// Called when a photo is successfully retrieved
//
function onPhotoDataSuccess(imageData) {
  // Uncomment to view the base64 encoded image data
  // console.log(imageData);

  // Get image handle
  //
  var smallImage = document.getElementById('smallImage');

  // Unhide image elements
  //
  smallImage.style.display = 'block';

  // Show the captured photo
  // The inline CSS rules are used to resize the image
  //
  smallImage.src = "data:image/jpeg;base64," + imageData;
}

// Called when a photo is successfully retrieved
//
function onPhotoURISuccess(imageURI) {
  // Uncomment to view the image file URI 
  // console.log(imageURI);

  // Get image handle
  //
  var largeImage = document.getElementById('largeImage');

  // Unhide image elements
  //
  largeImage.style.display = 'block';

  // Show the captured photo
  // The inline CSS rules are used to resize the image
  //
  largeImage.src = imageURI;
}

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

// A button will call this function
//
function capturePhotoEdit() {
  // Take picture using device camera, allow edit, and retrieve image as base64-encoded string  
  navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 20, allowEdit: true }); 
}

// A button will call this function
//
function getPhoto(source) {
  // Retrieve image file location from specified source
  navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50, 
    destinationType: destinationType.FILE_URI,
    sourceType: source });
}

// Called if something bad happens.
// 
function onFail(message) {
  alert('Failed because: ' + message);
}

这篇关于检索数据时的PhoneGap相机故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆