1
votes

I am working on a project in Titanium Alloy. I need to use the Beacon module to scan for beacons using BLE. My problem is that i can't get the module to work.

I used the Install mobile module to install the module and i enabled it in the tiapp.xml file.

This is the code i have at the moment:

var Beacons = require('com.logicallabs.beacons');

function doClick(beacon) {
    if(Beacons.BeaconsModule.isEnabled()){
        alert('succes');
    }else{
        alert("suces");
    }
}

$.index.open();

The function gets launched when you click a label. The module contains 3 classes. Do you have to specify wich method from which class you have to use?

Also when i start this program i get errors saying Could not find class 'android.bluetooth.BluetoothManager and Could not find class 'com.logicallabs.beacons.ScanService$2

2

2 Answers

0
votes

Here is slightly modified code from example app which is included in module which you installed:

var Beacons = require('com.logicallabs.beacons');

function log(text) {
    Ti.API.info(text);
}

if (Beacons.isSupported()) {
    log('Bluetooth is supported!');

    if (Beacons.isEnabled()) {
        log('Bluetooth is already enabled!');
    } else {
        log('Bluetooth is disbled; enabling now.');
        // This will eventually fire a stateChanged event with state set to
        // STATE_ON, at which point we start the scanning.
        Beacons.enable();
    }
} else {
    log('Bluetooth LE is not supported.');             
}

For more details check documentation and example app. On OSX you can find it in ~/Library/Application Support/Titanium/modules/android/com.logicallabs.beacons/ directory.

0
votes

It will only work if you test on a device with Android API version is >= 18