简体   繁体   English

构建后PhoneGap摄像头无法正常工作-Android

[英]PhoneGap camera not working after build - Android

I've been making an app that makes use of the camera using phonegap. 我一直在开发一个通过phonegap使用摄像头的应用程序。 When I test the app through my device via eclipse the app launches and everything works great on my phone. 当我通过eclipse在设备上测试应用程序时,该应用程序将启动,并且一切在手机上都能正常运行。

Once I run the phoneGap build service and download and test the app, everything works great except clicking on capture photo or get from library doesn't do anything. 一旦我运行phoneGap构建服务并下载并测试了该应用程序,一切都将运行良好,除了单击捕获的照片或从图库中获取不会执行任何操作。 Any ideas why it would work before the build, but not after it? 有什么想法为什么它会在构建之前起作用,而不是在构建之后起作用?

code removed 代码已删除

Clint, 克林特

First, a why: I suspect the reason that you were seeing a difference between actual build packages from Phonegap and the results from Eclipse is that your local build will be "slower" (due to debugging information in the package, or extra weight on the android device because of the adb process from eclipse... etc.) this is thus giving the DOM time to complete before the JS thread tries to seek those elements via jQuery. 首先,原因:我怀疑您发现Phonegap的实际构建包与Eclipse的结果之间存在差异的原因是,本地构建的速度会变慢(由于该包中的调试信息,或者该包的重量过大) android设备,因为eclipse的adb进程等),因此在JS线程尝试通过jQuery查找这些元素之前给了DOM时间。

As you worked out, the "correct way" to handle this would be to keep your external var definitions where they are... 当您解决问题时,处理此问题的“正确方法”是将外部var定义保留在原处...

// buttons for capturing and browsing for photo and uploading
        var capture_btn;   //     = $('#capture');     \
        var getImg_btn;    //     = $('#getImg');       >  do these later.
        var uploadImg_btn; //     = $('#uploadImg');   /

And then... 接着...

function onDeviceReady() {
    // now allocate DOM to buttons
        capture_btn    = $('#capture');    //
        getImg_btn     = $('#getImg');     // 'var'less, to keep in global scope
        uploadImg_btn  = $('#uploadImg');  //
    // rest of deviceReady as already written

You obviously "got it working" (YAY!) but hopefully this explains (with a wee bit more detail) why you were seeing differing results between live APKs and a local debugbuild and this fuller answer will help others in the future... :) 您显然“可以正常工作”(是!),但是希望这能(更详细地解释)为什么您在实时APK和本地debugbuild之间看到不同的结果,而更全面的答案将在将来对其他人有所帮助...: )

-TTFN and happy hacking, -TTFN和快乐的黑客入侵,

Dx :) Dx :)

Turns out the answer was simple. 原来答案很简单。 My variables for camera functions were called before the DOM loaded them. 我的相机功能变量在DOM加载之前被调用。

// buttons for capturing and browsing for photo and uploading
        var capture_btn    = $('#capture');
        var getImg_btn     = $('#getImg');
        var uploadImg_btn  = $('#uploadImg');

So it never even registered the clicks. 因此,它甚至从未注册过点击。 Weird part is that it worked when testing through eclipse. 奇怪的是,它在通过Eclipse测试时有效。

I added all of my camera controls into the deviceready event and viola. 我将所有相机控件添加到deviceready事件和中提琴中。 It works as it should. 它可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM