尝试使用PhoneGap创建入门应用。我被困在这条线上:
navigator.device.capture.captureAudio(onSuccess, onError, {limits:1, duration:5});
它在iOS上工作正常但在Android模拟器上抛出此错误:
无法读取未定义
的属性'capture'
这是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": {}
}
任何想法如何超越这个?
答案 0 :(得分:2)
好的,这是我偶然发现的最愚蠢的解决方案!
Android的JS与iOS的不同。这些文件的名称相同 - phonegap-x.x.x.js
。对于其他所有移动平台而言,没有必要猜测它。
我知道你需要为不同的平台提供不同的JS,但是如何在某处提到它呢?
一旦我从Android文件夹拖动JS,一切都落到了位置。
感谢您回答这个问题:deviceready won't fire in Phonegap 1.0.0 on Android
答案 1 :(得分:0)
www目录中的phonegap.js文件名是否与index.html参考相匹配?一旦我将phonegap.js更改为phonegap-1.3.0.js,the API docs的完整示例就会在我的HTC evo上运行