Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Using Vibration plugin in Phonegap

    • 0
    • 1
    • 1
    • 1
    • 0
    • 0
    • 0
    • 0
    • 525
    Comment on it

    By using cordova-plugin-vibration we can get vibration on the devices. The plugin has some global objects like navigator.vibrate.

    Installation:

    cordova plugin add cordova-plugin-vibration
    

    Vibrate: The vibrate function provides the three functionalities that we can use to vibrate the devices.

    Standard Vibrate: It vibrates the device for a given period of time.

    navigator.vibrate(time)
    

    or

    navigator.vibrate([time])
    

    -time: in milliseconds

    for Example:

    navigator.vibrate(2000);            //vibrate for 2 seconds
    or
    navigator.vibrate([2000]);          //vibrate for 2 seconds
    

    Vibrate with a pattern:

    It is only for the Android and Windows.

    navigator.vibrate(pattern);
    

    we can vibrate the device with a specific pattern by using this.

    Pattern:It defines the durations (in milliseconds) of vibration in sequences for which we can turn on or turn off the vibration.

    Example:

    // Vibrate for 5 second
    // Wait for 3 second
    // Vibrate for 2 seconds
    // Wait for 1 second
    // Vibrate for 6 seconds
    navigator.vibrate([5000, 3000, 2000, 1000, 6000]);
    

    Cancel vibration:It is not supported in IOS

    It will cancel the vibration that is currently running on the device.

    navigator.vibrate(0)
    

    or

    navigator.vibrate([])
    

    or

    navigator.vibrate([0])
    

    That means we can pass an empty array or parameter 0 or an array with first element value 0. That will cancel any vibrations.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: