Phonegap错误 - "在Android上无法读取未定义的属性'捕获'

Mrc*_*ief 5 javascript android javascript-framework cordova

尝试使用PhoneGap创建启动应用程序.我被困在这条线上:

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

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

无法读取未定义的属性"捕获"

navigator是错误发生时的对象(注意没有device导致此错误的属性)

{
    "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": ""
}
Run Code Online (Sandbox Code Playgroud)

这是加载PhoneGap后的对象Phonegap.js(注意它说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": {}
}
Run Code Online (Sandbox Code Playgroud)

任何想法如何通过这个?

Mrc*_*ief 2

好吧,这是我偶然发现的最糟糕的解决方案!

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

我知道你需要为不同的平台使用不同的 JS,但是在某个地方提到这一点怎么样?

当我从 Android 文件夹中拖拽 JS 后,一切就都到位了。

感谢这个问题的回答:deviceready won't fire in Phonegap 1.0.0 on Android