Phonegap Error - “无法读取未定义的属性'捕获'在Android上 [英] Phonegap Error - "Cannot read property 'capture' of undefined" on Android

查看:114
本文介绍了Phonegap Error - “无法读取未定义的属性'捕获'在Android上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用PhoneGap创建入门应用。我被困在这一行:

Trying to create a starter app with PhoneGap. I'm stuck on this line:

navigator.device.capture.captureAudio(onSuccess,onError,{limits:1,duration:5} );

在iOS上工作正常但在Android模拟器上抛出此错误:

It works fine on iOS but throws this error on Android emulator:

无法读取未定义的属性'capture'

Cannot read property 'capture' of undefined

这是导航器对象,在出错时(注意没有设备属性导致此错误)

Here's navigator object, at the time of error (notice there's no device property which is causing this error)

{
    "language": "en-US",
    "product": "Gecko",
    "mimeTypes": {
        "length": 0
    },
    "appVersion": "5.0 (Linux; U; Android 4.0.3; en-us; sdk Build/MR1) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30",
    "plugins": {
        "length": 0
    },
    "onLine": true,
    "connection": {
        "type": 0
    },
    "platform": "Linux armv7l",
    "vendor": "Google Inc.",
    "appCodeName": "Mozilla",
    "geolocation": {},
    "cookieEnabled": true,
    "appName": "Netscape",
    "productSub": "20030107",
    "userAgent": "Mozilla/5.0 (Linux; U; Android 4.0.3; en-us; sdk Build/MR1) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30",
    "vendorSub": ""
}

这是 PhoneGap 对象,紧跟在 Phonegap.js 已加载(注意它说 device:true

And here's the PhoneGap object just after Phonegap.js has loaded (notice it says device: true)

{
    "commandQueue": [],
    "commandQueueFlushing": false,
    "_constructors": [
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null,
        null
    ],
    "documentEventHandler": {},
    "windowEventHandler": {},
    "resources": {
        "base": true,
        "debugconsole": true,
        "position": true,
        "acceleration": true,
        "accelerometer": true,
        "battery": true,
        "camera": true,
        "device": true,
        "capture": true,
        "contact": true,
        "file": true,
        "filetransfer": true,
        "geolocation": true,
        "compass": true,
        "media": true,
        "notification": true,
        "orientation": true,
        "sms": true,
        "telephony": true,
        "network": true,
        "splashscreen": true
    },
    "available": false,
    "sessionKey": 0,
    "callbackId": 0,
    "callbacks": {},
    "callbackStatus": {
        "NO_RESULT": 0,
        "OK": 1,
        "CLASS_NOT_FOUND_EXCEPTION": 2,
        "ILLEGAL_ACCESS_EXCEPTION": 3,
        "INSTANTIATION_EXCEPTION": 4,
        "MALFORMED_URL_EXCEPTION": 5,
        "IO_EXCEPTION": 6,
        "INVALID_ACTION": 7,
        "JSON_EXCEPTION": 8,
        "ERROR": 9
    },
    "mediaObjects": {}
}

任何想法如何超越这个?

Any ideas how to get past this?

推荐答案

好的,这个是我偶然发现的最愚蠢的解决方案!

Ok, this is the most douchy solution I ever stumbled upon!

Android的JS与iOS的不同。这些文件的名称相同 - phonegap-x.x.x.js 。没有必要猜测每个其他移动平台都有所不同。

The JS for Android is different than that for iOS. The files is named the same though - phonegap-x.x.x.js. No points for guessing it'd be different for every other mobile platform.

我知道你需要为不同的平台提供不同的JS,但是如何在某个地方提到它?

I understand that you need to have different JS for different platform, but how about mentioning that somewhere?

一旦我从Android文件夹中拖动JS,一切都落到了位置。

Once I dragged the JS from Android folder, everything fell into place.

感谢这个问题的答案: deviceready将无法在Android上的Phonegap 1.0.0中触发

Thanks to this question for the answer: deviceready won't fire in Phonegap 1.0.0 on Android

这篇关于Phonegap Error - “无法读取未定义的属性'捕获'在Android上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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