If you find any errors, typos or have general feedback, select the text and click CTRL+ALT+ENTER.

Introduction

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

Design

1. Open your Appery.io Bootstrap/AngularJS or Ionic/AngularJS project or create a new one. You will get two default pages: indexand Screen1.

2. Go to Screen1 and add a Button component to the page, with its Text = Vibro and ng-click = vib().

If you are new to using Bootstrap/AngularJS and/or Ionic/AngularJS UI components, read here and here respectively.

Now, let’s create services and variables and bind them with UI components.

Scope

1. First, go to SCOPE and add a Vibration plugin for Android: in the builder, go to Project > CREATE NEW > From Plugin.

2. Select Apperyio Vibration Service and click Import selected plugins.

3. In the Project view, a list of related services and a JavaScript file appears.

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.

6. Select 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.

The click on the upper mapping button defines the service request, the lower one – the service response:

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.

Testing options:

Android

  1. 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.
  2. 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.

iOS

iOS options:

  1. 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.
  2. Build the app and install it on your device.