I'm submitting a ... (check one with "x")
[x] bug report
[ ] feature request
[ ] support request
Current behavior:
Uncaught TypeError: Object(...) is not a function
at Vibration.vibrate (vendor.js:85458)
at 5.js:102
at Object.callbackFromNative (cordova.js:291)
at <anonymous>:1:9
Expected behavior:
should vibrate phone for 1 second.
Steps to reproduce:
this.vibration.vibrate(1000);
Related code:
import { Vibration } from '@ionic-native/vibration/ngx';
constructor(private vibration: Vibration) {}
exampleFunc () {
this.vibration.vibrate(1000);
}
Other information:
I've added it in my a.module.ts file:
import { Vibration } from '@ionic-native/vibration/ngx';
...
providers: [
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler},
Vibration
]
Ionic info: (run ionic info from a terminal/cmd prompt and paste output below):
Ionic:
ionic (Ionic CLI) : 4.12.0 (/usr/local/lib/node_modules/ionic)
Ionic Framework : ionic-angular 3.9.3
@ionic/app-scripts : 3.2.1
Cordova:
cordova (Cordova CLI) : 8.1.2 ([email protected])
Cordova Platforms : android 7.1.4
Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 3.1.2, (and 6 other plugins)
System:
Android SDK Tools : 26.1.1 (/media/ntfs/android-sdk-linux)
NodeJS : v8.11.3 (/usr/local/bin/node)
npm : 6.9.0
OS : Linux 4.15
I'm pretty sure I'm doing everything ok.
Either it really doesnt work or I'm missing some basic detail....
I followed this official documentation
If I console.log(this.vibration) I get:
Vibration {}
__proto__: IonicNativePlugin
constructor: 茠 Vibration()
vibrate: 茠 (time)
__proto__: Object
Did you install the plugin as well? It is not clear in the report. What are you testing this on?
Yes I've run this 2 commands:
ionic cordova plugin add cordova-plugin-vibration
npm install @ionic-native/vibration
it works using navigator.vibrate(1000);
thats why I posted in the ionic-native repo, because the problem is with this "native" implementation
@chrisgriffith hahaha I was already writing the answer :smile:
Testing on Android
@rodrigograca31 from where did you get the navigator, can u show complete sample code
@yazanOthman navigator is a global object..... the vibration plugin uses it...
https://github.com/apache/cordova-plugin-vibration
@rodrigograca31 thanks for the reply, I have already found about it.
I get an error also with navigator:
[log] - {"app":{}}
To Native Cordova -> Vibration vibrate INVALID ["options": [1000]]
Any ideas? Anybody managed to use vibration with capacitor?
I was having this issue too on Android 10 with a Samsung Galaxy S9 when using this.vibration.vibrate(1000);. For me the issue was the phone was in silent mode which also disabled the vibration. Once I put the phone in vibrate mode or enabled the ringtone sounds the command worked as expected. I'm using Ionic 6.13.1 with Cordova 10.0.0.
Most helpful comment
Yes I've run this 2 commands:
it works using
navigator.vibrate(1000);thats why I posted in the ionic-native repo, because the problem is with this "native" implementation
@chrisgriffith hahaha I was already writing the answer :smile: