This tutorial shows how to add the Vibration service to an AngularJS app.
Before you begin
Tutorial level: intermediate.
Prerequisites: an Appery.io account.
Apache Cordova (PhoneGap)
Apache Cordova (PhoneGap) is automatically included when you create a new project in Appery.io. The Vibration component used in Appery.io is the Vibration component from Apache Cordova.
Creating the app
1. Open your Appery.io Bootstrap/AngularJS or Ionic/AngularJS project or create a new one. You will get two default pages:
2. Go to
Screen1 and add a
Button component to the page, with its
Now, let’s create services and variables and bind them with UI components.
1. First, go to
SCOPE and add a Vibration plugin for Android: in the builder, go to
Project > CREATE NEW > From Plugin.
Apperyio Vibration Service and click Import selected plugins.
3. In the
4. After a native service has been added to the app, it can be called. Invoking a native service is very similar to invoking a REST service.
To call the added service, go to the
SCOPE view of the
Screen1 page, add a new function –
vib and click Edit, opening the function editor.
5. Next, use the snippet
Invoke service: from the drop-down, select
Invoke service, delete the text
“service_name” in the code and click
CTRL+SPACE to get the drop-down with all the available services.
Instead of invoking services in the code editor with subsequent auto completing, you can use a drag and drop feature to invoke services. Read here to learn how.
Notification_vibrate service. After auto completing, the service is added to the function code and you can click Mapping to map the service to the page.
There are no response parameters, and the only optional request parameter –
duration. It is set in milliseconds and by default it equals 2000. Please find more here.
Testing the app should be done on the device.
- Use the Appery.io Mobile Tester app. It’s an app that allows you to launch any app created in Appery.io as a hybrid app. You can find it in the Google Play Store.
- Build the Android binary and install it your device. When the build is completed, you’ll see a QR code. Scanning the QR code will download the app to your phone. You can also email the app to your device.