javascript - 未捕获的类型错误 : Object #<Object> has no method 'vibrate'

标签 javascript android cordova cordova-plugins android-vibration

我在 cordova 3.4.0 for android 上创建了一个 hello world 项目。不知何故,我的对话框/通知插件无法正常工作。我是这样添加插件的

cordova plugin add org.apache.cordova.dialogs

并在我的 android list 中添加了这一行:

<uses-permission android:name="android.permission.VIBRATE" />

当我测试插件时,它的方法“警报”、“提示”、“确认”和“蜂鸣”非常有效,但是一旦我想调用振动方法,就像我在 Cordova API 中读到的那样它崩溃了。这是我的代码:

$(document).ready(function(){
   document.addEventListener("deviceready", function() {
      navigator.notification.vibrate(1000);
   }, false);
})

我在 logcat 中遇到此错误消息:

Uncaught TypeError: Object #<Object> has no method 'vibrate'

我像这样注销了 navigator.notification 的所有方法:

var res = [];
for(var m in navigator.notification) {
     if(typeof navigator.notification[m] == "function") {
        res.push(m)
     }
}
console.log(res);

结果:“alert,confirm,prompt,beep,activityStart,activityStop,progressStart,progressStop,progressValue”

有谁知道为什么 navigator.notification 中没有振动方法?

编辑

我的 res/config.xml 中有这个条目:

<feature name="Notification">
    <param name="android-package" value="org.apache.cordova.dialogs.Notification" />
</feature>

最佳答案

出于某种原因,振动不再包含在通知插件中,而是包含在一个额外的插件中:

https://github.com/apache/cordova-plugin-vibration/blob/master/doc/index.md

关于javascript - 未捕获的类型错误 : Object #<Object> has no method 'vibrate' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24241764/

相关文章:

javascript - 我无法在 Sails.js 上建立简单的关联(关系模型的字段显示未定义)

jquery - jquery如何在下拉列表中添加值

java - 是否可以在Alertdialog中创建GridView?

android - 无法播放 Assets "it is probably compressed"中的音频

java - 错误 :(30, 0) 找不到参数的方法compile()

ios - Xcode 项目中不包含 Ionic/Cordova 插件

android - 如何防止 Oculus Home 在插入 Gear VR 时接管 Cordova+React VR 应用程序

javascript - 无法让 gulp-notify 在 gulp-jshint 失败时弹出错误消息

javascript - ReactJS return 语句中出现意外标记

javascript - 将像素转换为分钟