Beacons implementation for Android in Titanium
Posted By : Akshay Luthra | 30-Dec-2014
Beacon is Bluetooth low-energy (BLE) wireless technology to create a different way of providing location-based information and services to Android devices. The beacons themselvers are small, cheap Bluetooth transmitters. Apps installed on your Android listen out for the signal transmitted by these beacons and responds accordingly when the phone comes into range.
To use Beacon, you need Android 4.3 and above, Bluetooth turned on, and a compatible Android device.
Each Beacon has 3 entries to distinguish them -
- UUID
- Major ID
- Minor ID
The UUID is an unique identifier. For example, if Big Bazaar decides to deploy beacon sensors inside its store and make an app that can tell the user once they arrive at a specific store, they would define a UUID that is unique to their app and the beacons inside their stores. Inside the stores, they would place beacon devices and configure each of them to use a different “minor” value. For example, at the store A, they would place all beacon devices broadcasting the Starbucks UUID, major value 0, minor 1 near the door, minor 2 near the mugs display and minor value 3 near the cashier. At store B, they would use the same UUID, but major 1 and minor values according to the location inside the store.
Now to implement the Beacons functionality for Android in Titanium, you need to download the latest module from the link "http://gitt.io/component/com.liferay.beacons" and include that module in your "tiapp.xml" .
Then in your "app.js" file write the code -
// this sets the background color of the master UIView
Titanium.UI.setBackgroundColor('#000');
var TiBeacons = require("com.liferay.beacons");
var win = Ti.UI.createWindow({
backgroundColor : '#fff'
});
TiBeacons.startMonitoringForRegion({
uuid : < your beacon UUID >,
identifier : < your beacon Identifier >,
major : < your beacon major >,
minor : < your beacon minor >,
});
TiBeacons.addEventListener("enteredRegion", function(e) {
Ti.API.info("enteredRegion" + JSON.stringify(e));
});
TiBeacons.addEventListener("exitedRegion", function(e) {
Ti.API.info("exitedRegion" + JSON.stringify(e));
});
TiBeacons.addEventListener("determinedRegionState", function(e) {
Ti.API.info("determinedRegionState" + JSON.stringify(e));
});
win.open();
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Akshay Luthra
Akshay Luthra has excellent experience in developing Cross Platform Mobile Apps using JavaScript and Titanium Framework. He loves listening to music and travelling new places.