Phonegap 错误 - “无法读取属性‘捕获’”未定义的”在安卓上
尝试使用 PhoneGap 创建一个入门应用程序。我被困在这一行:
navigator.device.capture.captureAudio(onSuccess, onError, {limits:1,uration: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": ""
}
这是 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": {}
}
有什么想法如何解决这个问题吗?
Trying to create a starter app with PhoneGap. I'm stuck on this line:
navigator.device.capture.captureAudio(onSuccess, onError, {limits:1, duration:5});
It works fine on iOS but throws this error on Android emulator:
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": ""
}
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,这是我偶然发现的最糟糕的解决方案!
Android 的 JS 与 iOS 的 JS不同。不过,这些文件的名称相同 -
phonegap-xxxjs
。没有必要猜测其他移动平台的情况会有所不同。我知道你需要为不同的平台使用不同的 JS,但是在某个地方提到这一点怎么样?
当我从 Android 文件夹中拖动 JS 后,一切就都到位了。
感谢这个问题的回答: deviceready won't fire in Android 上的 Phonegap 1.0.0
Ok, this is the most douchy solution I ever stumbled upon!
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.I understand that you need to have different JS for different platform, but how about mentioning that somewhere?
Once I dragged the JS from Android folder, everything fell into place.
Thanks to this question for the answer: deviceready won't fire in Phonegap 1.0.0 on Android
www 目录中的phonegap.js 文件名是否与index.html 引用匹配?一旦我将phonegap.js更改为phonegap-1.3.0.js,完整示例来自 API 文档 在我的 HTC evo 上运行
Does the phonegap.js filename in your www directory match the index.html reference? Once I change the phonegap.js to phonegap-1.3.0.js, the full example from the API docs runs on my HTC evo