Add Vibration in Ionic 7 Angular with Ionic Native & Cordova

Last Updated on by in Ionic

In this Ionic Angular tutorial, you will learn how to add vibration in the Ionic application step by step using Ionic Native and Cordova packages.

Vibrating a device heralds the coming messages, notifications, or even an important call.

All the modern devices come with this feature; likewise, it should be enabled programmatically.

The vibration in Ionic is possible with Cordova and Ionic Native plugins.

It works smoothly in Android, iOS, and Windows by accessing vibration plugins in various methods.

Let’s start implementing the vibration feature in the Ionic application.

Setting up Ionic Environment

Ionic development starts with installing the Ionic command-line-interface tool (CLI).

It’s a foundational tool for Ionic app development. Run the below command to install it globally.

sudo npm install -g @ionic/cli

The below command helps you confirm the ionic version:

ionic --version

Create a new Angular Ionic blank project:

ionic start ionic-vibration-example blank --type=angular

Head over to project root:


Run the below command to add the native core package.

npm install @ionic-native/core --legacy-peer-deps

Disable Strict Type Errors

To avoid TypeScript compiling issues, we just need to open tsconfig.json file:

First, set below property under “compilerOptions” property.

"compilerOptions": {
    "strictPropertyInitialization": false,
    "skipLibCheck": true

Secondly, add given props under “angularCompilerOptions”.

"angularCompilerOptions": {
    "strictTemplates": false,

Install & Configure Ionic Native and Cordova Vibration Package

Once the Ionic project has been installed, right after that, execute both the commands simultaneously through the console.

To install the Ionic native and Cordova vibration plugin.

npm i cordova-plugin-vibration --legacy-peer-deps
npm install @ionic-native/vibration --legacy-peer-deps

Theoretically, you have to import the Vibration package from ‘@ionic-native/vibration/ngx’ in the main app.module.ts file.

Also inject the Vibration service in providers array to integrate the service in Ionic.

Implement Vibration in Ionic

All the time taking work has been done, now start integrating the Vibration in the Ionic project.

Move to file, in here; you have to invoke the adding vibration process by importing the Vibration service at the top. Also, inject the Vibration in the constructor() method.

It will allow you to access vibrate methods in the Ionic application.

import { Component } from '@angular/core';
import { Vibration } from '@ionic-native/vibration/ngx';

  selector: 'app-home',
  templateUrl: '',
  styleUrls: [''],
export class HomePage {
  constructor(private vibration: Vibration) {}

  invokeVibration(durationInMs: any) {

  vibratePattern(pattern: any) {

  reovkeVibration() {

The invokeVibration() method takes one parameter in milliseconds for evoking the vibration; it is all done with the vibrate method.

The vibratePattern() method allows the device to vibrate for a specified pattern.

Well, It is a type of sequence of durations (in milliseconds) for which to turn on or off the vibrator. However, it works for Android and Windows device only.

The revokeVibration() method stops the Vibration; however, it supports Android and Windows device only.

Call Vibration Events

Open the file and set up the Vibration events in the Home component.

<ion-header [translucent]="true">
      Ionic Vibration Example

<ion-content [fullscreen]="true">
  <h4>Vibrate Once</h4>
  <ion-button expand="full" (click)="invokeVibration()">Vibrate for 3 seconds</ion-button>

  <h4>Vibrate with pattern</h4>
  <ion-button expand="full" (click)="vibratePattern([1000, 1000, 3000, 1000, 5000])">Vibration Pattern</ion-button>

  <h4>Revoke Existing Vibration</h4>
  <ion-button expand="full" (click)="reovkeVibration()">Revoke vibration</ion-button>

Test Ionic Vibration App

For testing the Ionic vibration app, first, we need to add the platform using either of the below command based on our device choice.

# iOS
ionic cordova platform add ios

# Android
ionic cordova platform add android

# Windows
ionic cordova platform add windows

Next, run the below build command:

# iOS
ionic cordova build ios

# Android
ionic cordova build android

# Windows
ionic cordova build windows

The following command can help you test the app on a real device; also, you can debug the app in the Chrome browser. So, connect your device to the computer through USB and execute the command.

# iOS
ionic cordova run ios -l

# Android
ionic cordova run android -l

# Windows
ionic cordova run windows -l


So this was it; we have completed the Ionic Vibration tutorial; in this tutorial, we saw how to add a vibration feature in the Ionic application.

We also looked at various methods for handling the vibration using Ionic native and Cordova packages.

That’s all folks! Thanks for reading and don’t forget to share this tutorial with others.

Digamber - Author

Hi, I'm Digamber Singh, a New Delhi-based full-stack developer, tech author, and open-source contributor with 10+ years' experience in HTML, CSS, JavaScript, PHP, and WordPress.