从文档页面相机例如,在Android 2.3.x版本失败 [英] Camera example from the docs page fails on android 2.3.x

查看:122
本文介绍了从文档页面相机例如,在Android 2.3.x版本失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创造了Android手机captureing照片中的PhoneGap的应用程序。针对Android 4.x的其工作罚款但不工作为Android 2.3.x版本

得到了这样的错误:

对不起!
该应用程序AppName的(包名)已停止unexpectedly.please再试

我已经创建的项目作为提及<一个href=\"http://docs.phonegap.com/en/2.5.0/guide_getting-started_android_index.md.html#Getting%20Started%20with%20Android\"相对=nofollow>此处并使用完整的例子这里

我phonegep html页面是:


 &LT;!DOCTYPE HTML&GT;
&LT; HTML和GT;
&LT; HEAD&GT;
&LT;标题&GT;捕获照片&LT; /标题&GT;&LT;脚本类型=文/ JavaScript的字符集=utf-8SRC =科尔多瓦-2.5.0.js&GT;&LT; / SCRIPT&GT;
&LT;脚本类型=文/ JavaScript的字符集=utf-8&GT;VAR pictureSource; //图片来源
VAR destinationType; //设置返回值的格式//等待科尔多瓦与设备连接
//
document.addEventListener(deviceready,onDeviceReady,FALSE);//科尔多瓦是随时可以使用!
//
功能onDeviceReady(){
    pictureSource = navigator.camera.PictureSourceType;
    destinationType = navigator.camera.DestinationType;
}//如果照片是成功检索调用
//
功能onPhotoDataSuccess(为imageData){
  //取消注释查看的base64 EN codeD图像数据
  //执行console.log(为imageData);  //获取图像句柄
  //
  变种smallImage =的document.getElementById('smallImage');  //取消隐藏图像元素
  //
  smallImage.style.display =块;  //显示所拍摄的照片
  //内联CSS规则是用来调整图像大小
  //
  smallImage.src =数据:图像/ JPEG; BASE64,+为imageData;
}//如果照片是成功检索调用
//
功能onPhotoURISuccess(imageURI){
  //取消注释查看图像文件URI
  //执行console.log(imageURI);  //获取图像句柄
  //
  变种largeImage =的document.getElementById('largeImage');  //取消隐藏图像元素
  //
  largeImage.style.display =块;  //显示所拍摄的照片
  //内联CSS规则是用来调整图像大小
  //
  largeImage.src = imageURI;
}//一个按钮将调用这个函数
//
功能capturePhoto(){
  //将图片使用设备的摄像头和图像检索为base64-CN codeD字符串
  navigator.camera.getPicture(onPhotoDataSuccess,onFail,{质量:50,
    destinationType:destinationType.DATA_URL});
}//一个按钮将调用这个函数
//
功能capturePhotoEdit(){
  //将图片使用设备的摄像头,让编辑和图像检索为base64-CN codeD字符串
  navigator.camera.getPicture(onPhotoDataSuccess,onFail,{质量:20,allowEdit:真实,
    destinationType:destinationType.DATA_URL});
}//一个按钮将调用这个函数
//
功能getPhoto(源){
  //从指定源中检索图像文件位置
  navigator.camera.getPicture(onPhotoURISuccess,onFail,{质量:50,
    destinationType:destinationType.FILE_URI,
    sourceType的:源});
}//调用如果有什么不好的事情发生。
//
功能onFail(消息){
  警报('因为失败:'+消息);
}&LT; / SCRIPT&GT;
&LT; /头&GT;
&LT;身体GT;
&LT;按钮的onclick =capturePhoto();&GT;捕获照片&LT; /按钮&GT; &LT; BR&GT;
&LT;按钮的onclick =capturePhotoEdit();&GT;捕获编辑照片及LT; /按钮&GT; &LT; BR&GT;
&LT;按钮的onclick =getPhoto(pictureSource.PHOTOLIBRARY);肽从图片库&LT; /按钮&GT;&LT; BR&GT;
&LT;按钮的onclick =getPhoto(pictureSource.SAVEDPHOTOALBUM);&GT;从相册和LT; /按钮&GT;&LT; BR&GT;
&LT; IMG风格=显示:无;宽度:60像素,高度:60像素; ID =smallImageSRC =/&GT;
&LT; IMG风格=显示:无; ID =largeImageSRC =/&GT;
&LT; /身体GT;
&LT; / HTML&GT;

错误日志:

  05-16 14:51:38.249:E / AndroidRuntime(13459):致命异常:主要
05-16 14:51:38.249:E / AndroidRuntime(13459):了java.lang.RuntimeException:无法恢复活动{} com.name/package:了java.lang.RuntimeException:不提供结果ResultInfo {谁= NULL,请求= 34,结果= -1,数据= {意向(有临时演员)}}到活动{} com.name/com.name.namedemo:显示java.lang.NullPointerException
05-16 14:51:38.249:E / AndroidRuntime(13459):在android.app.ActivityThread.performResumeActivity(ActivityThread.java:2120)
    05-16 14:51:38.249:E / AndroidRuntime(13459):在android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2135)
    05-16 14:51:38.249:E / AndroidRuntime(13459):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1668)
    05-16 14:51:38.249:E / AndroidRuntime(13459):在android.app.ActivityThread.access $ 1500(ActivityThread.java:117)
    05-16 14:51:38.249:E / AndroidRuntime(13459):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:931)
    05-16 14:51:38.249:E / AndroidRuntime(13459):在android.os.Handler.dispatchMessage(Handler.java:99)
    05-16 14:51:38.249:E / AndroidRuntime(13459):在android.os.Looper.loop(Looper.java:130)
    05-16 14:51:38.249:E / AndroidRuntime(13459):在android.app.ActivityThread.main(ActivityThread.java:3683)
    05-16 14:51:38.249:E / AndroidRuntime(13459):在java.lang.reflect.Method.invokeNative(本机方法)
    05-16 14:51:38.249:E / AndroidRuntime(13459):在java.lang.reflect.Method.invoke(Method.java:507)
    05-16 14:51:38.249:E / AndroidRuntime(13459):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:875)
    05-16 14:51:38.249:E / AndroidRuntime(13459):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:633)
    05-16 14:51:38.249:E / AndroidRuntime(13459):在dalvik.system.NativeStart.main(本机方法)
    05-16 14:51:38.249:E / AndroidRuntime(13459):了java.lang.RuntimeException:由故障造成的结果交付{ResultInfo谁= NULL,请求= 34,结果= -1,数据= {意向(有临时演员)}}到活动{} com.name/com.name.namedemo:显示java.lang.NullPointerException
    05-16 14:51:38.249:E / AndroidRuntime(13459):在android.app.ActivityThread.deliverResults(ActivityThread.java:2532)
    05-16 14:51:38.249:E / AndroidRuntime(13459):在android.app.ActivityThread.performResumeActivity(ActivityThread.java:2107)
    05-16 14:51:38.249:E / AndroidRuntime(13459):... 12多
    05-16 14:51:38.249:E / AndroidRuntime(13459):致:显示java.lang.NullPointerException
    05-16 14:51:38.249:E / AndroidRuntime(13459):在org.apache.cordova.DroidGap.onActivityResult(DroidGap.java:849)
    05-16 14:51:38.249:E / AndroidRuntime(13459):在android.app.Activity.dispatchActivityResult(Activity.java:3908)
    05-16 14:51:38.249:E / AndroidRuntime(13459):在android.app.ActivityThread.deliverResults(ActivityThread.java:2528)
    05-16 14:51:38.249:E / AndroidRuntime(13459):... 13个
    05-16 14:51:39.039:W / WebCore的(13459):第一个布局后无法获得viewWidth


解决方案

默认的PhoneGap(科尔多瓦)摄像头插件调用本机摄像头,这使得Android的垃圾收集杀死后台应用程序。这个插件避免你的应用程序去背景,通过与其他应用程序的垃圾回收器被杀死。我们使用PhoneGap的源$ C ​​$ c和修改,以避免这个问题。此插件只能与文件URI的作品。

前景相机插件的PhoneGap

I am creating a phonegap app for captureing photo in android phones. Its working fine for android 4.x. but not working for android 2.3.x

got an error like this:

Sorry! The application AppName(packagename) has stopped unexpectedly.please try again

I 've created the project as the mentioned here and using the full example here.

My phonegep html page is:


<!DOCTYPE html>
<html>
<head>
<title>Capture Photo</title>

<script type="text/javascript" charset="utf-8" src="cordova-2.5.0.js"></script>
<script type="text/javascript" charset="utf-8">

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

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

// Cordova 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,
    destinationType: destinationType.DATA_URL });
}

// 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,
    destinationType: destinationType.DATA_URL });
}

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

</script>
</head>
<body>
<button onclick="capturePhoto();">Capture Photo</button> <br>
<button onclick="capturePhotoEdit();">Capture Editable Photo</button> <br>
<button onclick="getPhoto(pictureSource.PHOTOLIBRARY);">From Photo Library</button><br>
<button onclick="getPhoto(pictureSource.SAVEDPHOTOALBUM);">From Photo Album</button><br>
<img style="display:none;width:60px;height:60px;" id="smallImage" src="" />
<img style="display:none;" id="largeImage" src="" />
</body>
</html>

Error log:

05-16 14:51:38.249: E/AndroidRuntime(13459): FATAL EXCEPTION: main
05-16 14:51:38.249: E/AndroidRuntime(13459): java.lang.RuntimeException: Unable to resume activity {com.name/package}: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=34, result=-1, data=Intent { (has extras) }} to activity {com.name/com.name.namedemo}: java.lang.NullPointerException
05-16 14:51:38.249: E/AndroidRuntime(13459):    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2120)
    05-16 14:51:38.249: E/AndroidRuntime(13459):    at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2135)
    05-16 14:51:38.249: E/AndroidRuntime(13459):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1668)
    05-16 14:51:38.249: E/AndroidRuntime(13459):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
    05-16 14:51:38.249: E/AndroidRuntime(13459):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
    05-16 14:51:38.249: E/AndroidRuntime(13459):    at android.os.Handler.dispatchMessage(Handler.java:99)
    05-16 14:51:38.249: E/AndroidRuntime(13459):    at android.os.Looper.loop(Looper.java:130)
    05-16 14:51:38.249: E/AndroidRuntime(13459):    at android.app.ActivityThread.main(ActivityThread.java:3683)
    05-16 14:51:38.249: E/AndroidRuntime(13459):    at java.lang.reflect.Method.invokeNative(Native Method)
    05-16 14:51:38.249: E/AndroidRuntime(13459):    at java.lang.reflect.Method.invoke(Method.java:507)
    05-16 14:51:38.249: E/AndroidRuntime(13459):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:875)
    05-16 14:51:38.249: E/AndroidRuntime(13459):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:633)
    05-16 14:51:38.249: E/AndroidRuntime(13459):    at dalvik.system.NativeStart.main(Native Method)
    05-16 14:51:38.249: E/AndroidRuntime(13459): Caused by: java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=34, result=-1, data=Intent { (has extras) }} to activity {com.name/com.name.namedemo}: java.lang.NullPointerException
    05-16 14:51:38.249: E/AndroidRuntime(13459):    at android.app.ActivityThread.deliverResults(ActivityThread.java:2532)
    05-16 14:51:38.249: E/AndroidRuntime(13459):    at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2107)
    05-16 14:51:38.249: E/AndroidRuntime(13459):    ... 12 more
    05-16 14:51:38.249: E/AndroidRuntime(13459): Caused by: java.lang.NullPointerException
    05-16 14:51:38.249: E/AndroidRuntime(13459):    at org.apache.cordova.DroidGap.onActivityResult(DroidGap.java:849)
    05-16 14:51:38.249: E/AndroidRuntime(13459):    at android.app.Activity.dispatchActivityResult(Activity.java:3908)
    05-16 14:51:38.249: E/AndroidRuntime(13459):    at android.app.ActivityThread.deliverResults(ActivityThread.java:2528)
    05-16 14:51:38.249: E/AndroidRuntime(13459):    ... 13 more
    05-16 14:51:39.039: W/webcore(13459): Can't get the viewWidth after the first layout

解决方案

The default Phonegap (Cordova) Camera Plugin calls the native camera and this makes Android Garbage Collector to kill background applications. This plugin avoid your application to go background and be killed by Garbage Collector with other applications. We used the Phonegap source code and modified it to avoid this problem. This plugin works only with File URI.

Foreground Camera Plugin for Phonegap

这篇关于从文档页面相机例如,在Android 2.3.x版本失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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