Table of Contents
HopDroid
This documents the HopDroid JavaScript module that enables applications to access Android on-device features. Of course, this module is only useful for Hop Android installation, that is, Hop running on an Android divece.
Use require( hop.hopdroid )
to use it as a library.
Constructor
new hopdroid.phone()
Creates a custom phone
object. This object is required to access
device features and to install event listeners.
A phone
object posses the following attributes:
sdk
: the sdk name.model
: the phone model.product
: the product number.
Methods
phone.addEventListener( event, listener )
Installs an event listener for the phone. All events have an associated value whose components are stored in an array. The known events are:
battery
: An event denoting the state of the battery. The value associated with the event is an array containing:- the battery level, 2. the status, 3. the plug/unplug state, 4. the battery healt, 5. the battery voltage.
tts
:call
: An event denoting the call state.orientation
:connectivity
:proximity
:smssend
:smsdelivered
: Is emitted upon sms delivery. The value associated with the event is an array whose first element is the string"ok"
is the delivery has been sucessful.smsreceived
: Is emitted upon sms reception. The associated value is an array of two strings: the sender phone number and the message body.
phone.sendSms( number, text )
Sends an sms to phone number
. Example:
const hopdroid = require( hop.hopdroid );
const phone = new hopdroid.phone();
const phoneNumber = ...;
phone.sendSms( phoneNumber, "Sent from Hop.js" );
phone.placeCall( number )
Place a call to number
.
phone.stopCall( number )
Stop the current call.
phone.vibrate( frequency = 2, repetition = 1 )
Vibrate the phone. The argument frequency
can either be:
- an integer standing for the frequency of the vibration.
- an array of integers whose elements are vibration frequency separated by delays.
If repetition
is a positive integer, it tells how many times to repeat
the vibration. Example:
const hopdroid = require( hop.hopdroid );
const phone = new hopdroid.phone();
const dot = 200;
const dash = 500;
cont shortGap = 200;
const mediumGap = 500;
const longGap = 1000;
const sos = [ 0,
// S
dot, shortGap, dot, shortGap, dot,
// O
dash, shortGap, dash, shortGap, dash,
// S
dot, shortGap, dot, shortGap, dot,
longGap ];
phone.vibrate( sos );