相机与PhoneGap和Sencha触摸

时间:2012-07-19 06:29:01

标签: android cordova sencha-touch-2

我正在尝试使用Sencha触控相机,使用Phonegap移植到Android。正如Sencha touch guide to using native APIs建议的那样,我宣称相机是必需的: Ext.require('Ext.device.Camera');
但不幸的是,我收到了这个错误:

07-19 11:51:42.159: E/Web Console(8668): Uncaught Error: [Ext.Loader]
Failed loading './device/Camera.js', please verify that the file exists at 
file:///android_asset/www/lib/touch/sencha-touch-all-debug.js:8000

sencha库在设备下有Camera.js。我不确定为什么会出现这个错误。

修改1:仍然无法找到答案。非常感谢任何建议。

3 个答案:

答案 0 :(得分:1)

如果你下载了sencha touch的源代码,那么在“src”目录下会有一个名为“device”的目录(解压后)。 Camera.js在该目录中。似乎sencha-touch-all-debug.js或sencha-touch-all.js不包含“device”目录中所有.js文件的源代码。您必须手动将该目录复制到您的android资源目录(例如文件:/// android_asset / www / lib / touch / device)。

您可以在Android资产的任何位置复制目录设备(例如file:/// android_asset / www / device)。然后在使用sencha touch之前的第一个javascript声明中,您必须键入以下代码:

Ext.Loader.setConfig ({
     paths: {
         'Ext.device': 'device'
     }
});

代码告诉“Ext.device”是对目录“device”的引用。确保“device”目录相对于调用javascript的html文件(例如index.html)。从上面的代码中可以看出“device”目录与html文件的位置相同。

答案 1 :(得分:1)

如果您使用phonegap进行部署,请使用 Phonegap相机功能。我已经按照以下方式在我的应用中使用它了:

  1. 在index.html文件中添加<script type="text/javascript" src="cordova-x.x.x.js"></script>

  2. 使用以下代码打开相机:

    navigator.camera.getPicture( cameraSuccess, cameraError, [ cameraOptions ] );
    
  3. 有关此api的更多信息,请使用以下链接: http://docs.phonegap.com/en/edge/cordova_camera_camera.md.html#Camera

答案 2 :(得分:0)

在sencha论坛上有一个关于它的thread

问题似乎是Phongap - Cordova的命名。在加载Sencha Touch之前执行此操作应该可以解决这个问题。

if(typeof window.Cordova != 'undefined') {
    window.PhoneGap = window.Cordova;
}