PhoneGap 摄像头重启应用 [英] PhoneGap camera restarts the application

查看:16
本文介绍了PhoneGap 摄像头重启应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 PhoneGap 的 navigator.camera.getPicture 函数从 Android 设备的相机中检索照片.

I'm using PhoneGap's navigator.camera.getPicture function to retrieve a photo from the device's camera on Android.

function onSuccess(imageData) {
    alert("Success!");
}

function onFail(message) {
    alert('Failed because: ' + message);
}

$(function() {
    $("button").tap(function() {
        navigator.camera.getPicture(onSuccess, onFail, { quality: 50 }); 
    });
});

当我点击按钮时,它确实启动了相机,但是当我在拍照后点击相机应用上的确定"时,它会重新启动应用.

When I click the button, it does start the camera, but when I click OK on the camera app after taking a photo, it restarts the application.

我尝试过:

  • 使用不同的来源类型.
  • 使用不同的目的地类型.
  • 降低质量.

有什么想法吗?

我也开始 github 上的一个问题.

推荐答案

这个问题实际上与Phonegap 无关.这也是原生 Android 应用的常见问题.

This problem isn't actually about Phonegap. It's a common issue on native android apps too.

这是因为当相机被触发时,android Activity 进入后台(onStop 状态),等待相机拍照.然后 GC 来并在相机动作结束之前杀死活动以释放内存,当相机完成时,您的活动已经死亡.这就是应用重新启动的原因.

It occurs because when the camera is triggered, the android activity goes background (onStop state), waiting for the camera to take the picture. Then the GC comes and kills the activity to free memory before the conclusion of camera action, and when the camera is done your activity has already died. That is why the app is restarted.

它在 Android 生命周期文档(http://developer.android.com/reference/android/app/Activity.html):

It's on Android Lifecycle docs (http://developer.android.com/reference/android/app/Activity.html ):

如果一个活动被另一个活动完全遮挡,它就会停止.它仍然保留所有状态和成员信息,但是,它不再对用户可见,因此它的窗口是隐藏的,并且当其他地方需要内存时,它通常会被系统杀死.

If an activity is completely obscured by another activity, it is stopped. It still retains all state and member information, however, it is no longer visible to the user so its window is hidden and it will often be killed by the system when memory is needed elsewhere.

访问媒体库或导致您的活动进入后台的其他资源也会发生同样的情况.Phonegap(现为 Cordova)团队已经在努力改进这一点(https://issues.apache.org/jira/browse/CB-14).

The same occurs by acessing the media gallery or other resources that causes your activity to go background. Phonegap (now Cordova) team is already working to improve this ( https://issues.apache.org/jira/browse/CB-14 ).

我们公司遇到了这个问题,解决方案是本地开发一个 Phonegap 插件来使用我们定制的相机,然后我们的活动永远不会进入 onStop 状态.按照 http://developer.android.com/guide/topics/上的 android API 说明进行操作media/camera.html#custom-camera 也可以试试.

We had this problem in our company and the solution was to natively develop a Phonegap plugin to use our customized camera, then our activity never go to onStop state. Follow the android API instructions on http://developer.android.com/guide/topics/media/camera.html#custom-camera and try it too.

再见!

编辑 1:

我们提交了一个名为Foreground Camera Plugin的谷歌代码项目,修复了Android Camera重启Phonegap应用的问题.关于如何使用它也有一些方向.请参阅:http://code.google.com/p/foreground-camera-plugin/

We submited a Google Code project named Foreground Camera Plugin that fixes the problem of Android Camera restarting Phonegap applications. There is some orientation on how to use it too. Please see: http://code.google.com/p/foreground-camera-plugin/

编辑 2:

由于这个问题也发生在图库中,我们提交了另一个名为 Foreground Gallery Plugin 的 Google 代码项目,该项目与 Cordova 一起使用并修复了这个问题.请参阅:http://code.google.com/p/foreground-gallery-plugin/

Since this problem happens with gallery too, we submited another Google Code project named Foreground Gallery Plugin that works with Cordova and fixes this issue. Please see: http://code.google.com/p/foreground-gallery-plugin/

这篇关于PhoneGap 摄像头重启应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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