-
Notifications
You must be signed in to change notification settings - Fork 13
exercise use plugin
For the Beginner Workshop, we are using the PhoneGap Developer App instead of compiling our own app. The PhoneGap Developer App does not support installing plugins. However, it comes bundled with the official Apache Cordova plugins.
In this quick exercise, we will access the vibration plugin. You can use the PhoneGap CLI or the PhoneGap Desktop App. The instructions should be the same for both.
-
Create or open a Hello World project.
-
Pair it with the PhoneGap Developer App to preview the app.
-
Open
www/js/index.js
in your text editor. -
Locate lines 31 - 37:
31 // deviceready Event Handler 32 // 33 // The scope of 'this' is the event. In order to call the 'receivedEvent' 34 // function, we must explicitly call 'app.receivedEvent(...);' 35 onDeviceReady: function() { 36 app.receivedEvent('deviceready'); 37 }, ```
-
When the
deviceready
event fires, then PhoneGap is ready to access native plugins. -
Let's call the vibration plugin once the device is ready:
-
Locate lines 31 - 37:
31 // deviceready Event Handler 32 // 33 // The scope of 'this' is the event. In order to call the 'receivedEvent' 34 // function, we must explicitly call 'app.receivedEvent(...);' 35 onDeviceReady: function() { 36 app.receivedEvent('deviceready'); 37 navigator.vibrate(3000); // vibrate for 3 seconds 38 }, ```
- Save file and wait for the PhoneGap Developer App to reload.
- Vbrrrrrrr The device should have vibrated!