我正在创建一个使用cordova记录语音并保存在手机中的应用程序
我按照链接中的说明进行了操作
1)http://plugins.cordova.io/#/package/org.apache.cordova.media-capture
2)https://cordova.apache.org/docs/en/3.0.0/cordova_device_device.md.html
但它是说navigator.device没有定义
添加了有关设备cordova plugin add org.apache.cordova.device
的插件,但它仍显示相同的错误。
在Xml中(在app / res / xml / config.xml中)
<feature name="Device">
<param name="android-package" value="org.apache.cordova.Device" />
</feature>
(in app/AndroidManifest.xml)
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
仍显示navigator.device is undefined
我的代码是
function Fnrecord() {
debugger;
OpenModalDialog('Alert', 'Voice Recording' + navigator.device +, '80%', '20%');
navigator.device.capture.captureAudio(captureSuccess, captureError, { limit: 2 });
function captureSuccess(mediaFiles) {
var i, len;
for (i = 0, len = mediaFiles.length; i < len; i += 1) {
uploadFile(mediaFiles[i]);
}
}
// Called if something bad happens.
//
function captureError(error) {
var msg = 'An error occurred during capture: ' + error.code;
// navigator.notification.alert(msg, null, 'Uh oh!');
OpenModalDialog('Alert', msg, '80%', '20%');
}
// A button will call this function
//
function captureAudio() {
debugger;
var capture = navigator.device.capture;
OpenModalDialog('Alert', 'Voice Recording' + capture, '80%', '20%');
// Launch device audio recording application,
// allowing user to capture up to 2 audio clips
navigator.device.capture.captureAudio(captureSuccess, captureError, { limit: 2 });
}
// Upload files to server
function uploadFile(mediaFile) {
var ft = new FileTransfer(),
path = mediaFile.fullPath,
name = mediaFile.name;
ft.upload(path,
"http://my.domain.com/upload.php",
function (result) {
console.log('Upload success: ' + result.responseCode);
console.log(result.bytesSent + ' bytes sent');
},
function (error) {
console.log('Error uploading file ' + path + ': ' + error.code);
},
{ fileName: name });
}
}
答案 0 :(得分:1)
对我来说,问题是没有安装device
插件:
cordova plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-device.git