Coder Social home page Coder Social logo

apache / cordova-plugin-vibration Goto Github PK

View Code? Open in Web Editor NEW
126.0 23.0 127.0 770 KB

Apache Cordova Vibration Plugin

Home Page: https://cordova.apache.org/

License: Apache License 2.0

JavaScript 80.24% Objective-C 7.28% C# 12.48%
cordova library objective-c java nodejs javascript mobile android hacktoberfest ios

cordova-plugin-vibration's Introduction

title description
Vibration
Vibrate the device.

cordova-plugin-vibration

Android Testsuite Chrome Testsuite iOS Testsuite Lint Test

This plugin provides a way to vibrate the device. Its API aligns with the W3C vibration specification at http://www.w3.org/TR/vibration/

The plugin defines a global object/method navigator.vibrate. Although in the global scope, it is not available until after the deviceready event.

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
    console.log(navigator.vibrate);
}

Installation

cordova plugin add cordova-plugin-vibration

Supported Platforms

  • iOS
  • Windows Phone
  • Android
    The Android webview (API level 19 and up) supports the W3C Vibration API natively, so no Android specific implementation in this plugin is necessary.

navigator.vibrate

This function has three different functionalities based on parameters passed to it:

Standard vibrate

Vibrates the device for a given amount of time.

navigator.vibrate(time)

or

navigator.vibrate([time])
  • time: Milliseconds to vibrate the device. (Number)

Example

// Vibrate for 3 seconds
navigator.vibrate(3000);

// Vibrate for 3 seconds
navigator.vibrate([3000]);

Quirks

iOS Quirks
  • time: Ignores the specified time and vibrates for a pre-set amount of time.

    navigator.vibrate(3000); // 3000 is ignored
Windows Phone Quirks
  • time: Max time is 5000ms (5s) and min time is 1ms

    navigator.vibrate(8000); // will be truncated to 5000
Android Quirks

Calls to navigator.vibrate will immediately return false if user hasn't tapped on the frame or any embedded frame yet.

See https://www.chromestatus.com/feature/5644273861001216

Vibrate with a pattern

Vibrates the device with a given pattern

navigator.vibrate(pattern);
  • pattern: Sequence of durations (in milliseconds) for which to turn on or off the vibrator. (Array of Numbers)

Example

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

Quirks

  • Not supported on iOS

Cancel vibration

Immediately cancels any currently running vibration.

navigator.vibrate(0)

or

navigator.vibrate([])

or

navigator.vibrate([0])

Passing in a parameter of 0, an empty array, or an array with one element of value 0 will cancel any vibrations.

Quirks

  • Not supported on iOS

cordova-plugin-vibration's People

Contributors

agrieve avatar alsorokin avatar bennmapes avatar clelland avatar cmarcelk avatar dblotsky avatar dematerializer avatar erisu avatar filmaj avatar hardeep avatar hermwong avatar janpio avatar jcesarmobile avatar jsoref avatar ldeluca avatar macdonst avatar martincgg avatar master-of-magic avatar maverickmishra avatar purplecabbage avatar robpaveza avatar sgrebnov avatar shazron avatar sosahvictor avatar stacic avatar stevengill avatar surajpindoria avatar t1st3 avatar timbru31 avatar vladimir-kotikov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cordova-plugin-vibration's Issues

navigator.vibrate() Does not work in IOS 12.2

Bug Report

There is no error shown

Problem

navigator.vibrate() Does not work in IOS 12.2

What is expected to happen?

the phone should vibrate

What does actually happen?

the phoneDoes not vibrate

Information

Command or Code

navigator.vibrate()

Environment, Platform, Device

Cordova IOS 5.0.1
cordova-plugin-vibration 3.1.0 "Vibration"

Version information

Ionic:

ionic (Ionic CLI) : 4.1.2 (/usr/local/lib/node_modules/ionic)
Ionic Framework : ionic-angular 3.9.5
@ionic/app-scripts : 3.1.8

Cordova:

cordova (Cordova CLI) : 8.1.2 ([email protected])
Cordova Platforms : ios 5.0.1
Cordova Plugins : cordova-plugin-ionic-keyboard 2.0.5, cordova-plugin-ionic-webview 2.4.1, (and 23 other plugins)

System:

Android SDK Tools : 26.0.2 (/Users/afscdev/Library/Android/sdk)
ios-deploy : 1.9.2
ios-sim : 8.0.1
NodeJS : v11.8.0 (/usr/local/bin/node)
npm : 6.5.0
OS : macOS
Xcode : Xcode 10.2.1 Build version 10E1001

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

No vibrations on Android 10 devices

Bug Report

Problem

What is expected to happen?

Vibrations.

What does actually happen?

No vibrations.

Command or Code

constructor(private vibration: Vibration)
{
	this.isvcVibration.vibrate(200);
}

Environment, Platform, Device

Only tested on Android devices. Everything is working fine until I use a Android 10 device. I have tested only on 2 Android 10 devices and both doesn't vibrate.
Little detail: If I click on the overwiew button (the right physic button on the bottom of the screen), the device vibrates when the app goes in background.

Version information

cordova-plugin-vibration: 3.1.1.
cordova-android: 9.0.0
cordova-plugin-androidx: 3.0.0
cordova-plugin-androidx-adapter: 1.1.1
I use the Ionic framework

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

Vibration in background

Feature Request

Motivation Behind Feature

Using background vibration will be great for apps that want to get the user’s attention.

Feature Description

Possibility to perform vibration when the application is in the background.

Alternatives or Workarounds

I tried use Background plugin but doesn't work.

Vibrate not working on Android 4.4.2 with Ionic 3 or 4

Bug Report

When I opened debug in Android studio shows me that...

Connecting to io.ionic.tester
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
V/Provider/Settings: get setting for user 0 by user 0 so skipping cache
invalidate [system]: current 51 != cached 0
D/ActivityThread: hoder:android.app.IActivityManager$ContentProviderHolder@42c9b3c8,provider,holder.Provider:android.content.ContentProviderProxy@42c9bb40
V/Provider/Settings: from db cache, name = anr_debugging_mechanism , value = 1
D/asset: AssetManager-->addDefaultAssets CIP path not exsit!
W/ActivityThread: Application io.ionic.tester is waiting for the debugger on port 8100...
I/System.out: Sending WAIT chunk
I/dalvikvm: Debugger is active
A/libc: Fatal signal 11 (SIGSEGV) at 0x0000000a (code=1), thread 13232 (io.ionic.tester)

Problem

My phone is not vibrated.

What is expected to happen?

When I click to my button I am expecting to vibrate.

What does actually happen?

Nothing

Information

Local Notification with the options vibrate is working but not this plugin.

Command or Code

--type="ionic-angular" 
ionic cordova plugin add cordova-plugin-vibration
npm install --save @ionic-native/vibration@4
app.module.ts
import { Vibration } from '@ionic-native/vibration';

providers: [ ....
Vibration ....]

home.ts
import { Vibration } from '@ionic-native/vibration';
...
constructor(private vibration: Vibration){}

vibrate(){
    this.vibration.vibrate(2000);
  }

home.html
<button ion-button (click)="vibrate()" color="warning" full>Vibration</button>

in a similar (not same) way for --type="angular" 
ionic cordova plugin add cordova-plugin-local-notification
npm install @ionic-native/local-notifications
etc...

Environment, Platform, Device

My physical device Android 4.4.2 (kitkat)

Version information

Cordova: 8.1.2 ([email protected])
Ionic: 4.10.3
Tested on --type="angular" and --type="ionic-angular"

Checklist

  • [ yes] I searched for existing GitHub issues
  • [yes ] I updated all Cordova tooling to most recent version
  • [yes ] I included all the necessary information above

Vibration not Working in Android

Bug Report

Problem

The vibration plugin is not working in Android .

What is expected to happen?

What does actually happen?

Information

Command or Code

Environment, Platform, Device

Version information

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

Vibration not working on iPhone 11

Bug Report

No vibration on iPhone 11 Pro, iOS 13.3.1

Problem

navigator.vibrate does not vibrate phone

What is expected to happen?

App should vibrate when function called

What does actually happen?

App does not vibrate

Information

navigator.vibrate(200) as well as navigator.vibrate([200]) on iPhone 11 Pro, iOS 13.3.1 has no effect.

Command or Code

navigator.vibrate(200) as well as navigator.vibrate([200]) on iPhone 11 Pro, iOS 13.3.1 has no effect.

Environment, Platform, Device

iPhone 11 Pro, iOS 13.3.1

Version information

9.0.0 ([email protected])

Checklist

  • I searched for existing GitHub issues
  • [x ] I updated all Cordova tooling to most recent version
  • [x ] I included all the necessary information above

No automated tests

The tests in tests/tests.js are all manual tests, on CI nothing is executed as a result.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.