Search code examples
javascriptandroidcordovacordova-pluginsandroid-vibration

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


I created a hello world project on cordova 3.4.0 for android. Somehow my dialogs/notifications plugin does not work correctly. I added the plugin like this

cordova plugin add org.apache.cordova.dialogs

and added this line in my android manifest:

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

When I tested the plugin it worked really good with it's methods "alert", "prompt", "confirm" and "beep", but as soon as I want to call the vibrate method like I read in the Cordova API it crashes. Here is my code:

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

I run into this error message in the logcat:

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

I logged out all methods of navigator.notification like this:

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

The Result: "alert,confirm,prompt,beep,activityStart,activityStop,progressStart,progressStop,progressValue"

Does anyone have an idea why there is no vibrate method in navigator.notification ?

EDIT

I have got this entry in my res/config.xml:

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

Solution

  • For some reason vibration isn't included in the notification plugin anymore but in an extra plugin instead:

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