Skip to content
This repository was archived by the owner on Jan 5, 2021. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@ From the command prompt go to your app's root folder and execute:

```
tns plugin add nativescript-estimote-sdk
```

For Android, add these permissions into app/App_Resources/AndroidManifest.xml
```
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
```

## Methods
Expand All @@ -34,7 +41,7 @@ You can initialize the plugin for a region in the following way:
callback : function(beacons){
/* This is called everytime beacons are discovered or proximity changes

for (var i = 0; i < beacons.count; i++) {
for (var i = 0; i < beacons.length; i++) {
var beacon = beacons[i];
if (beacon.major > 0){
var distance = "NA";
Expand Down
101 changes: 51 additions & 50 deletions Plugin/estimote.android.js
Original file line number Diff line number Diff line change
@@ -1,70 +1,71 @@
global.ESTIMOTE_PROXIMITY_UUID = java.util.UUID.fromString("B9407F30-F5F8-466E-AFF9-25556B57FE6D");
global.ESTIMOTE_REGION_NAME = "default";


var Estimote = (function(){

function Estimote(options){
this._regionName = ESTIMOTE_REGION_NAME;
this.callback = options.callback;
function Estimote(options){
this._regionName = ESTIMOTE_REGION_NAME;
this._proximityUUID = options.proximityUUID ? java.util.UUID.fromString(options.proximityUUID) : ESTIMOTE_PROXIMITY_UUID;
this.callback = options.callback;

if (typeof options.region !== 'undefined'){
this._regionName = region;
}
var app = require("application");
if (typeof options.region !== 'undefined'){
this._regionName = options.region;
}
var app = require("application");

this.context = app.android.context;
this.context = app.android.context;

this.region = new com.estimote.sdk.Region(this._regionName, ESTIMOTE_PROXIMITY_UUID, null, null);
this.region = new com.estimote.sdk.Region(this._regionName, this._proximityUUID, null, null);

this.beaconManager = new com.estimote.sdk.BeaconManager(this.context);
this.beaconManager = new com.estimote.sdk.BeaconManager(this.context);

var _this = this;
var _this = this;

this.beaconManager.setRangingListener(new com.estimote.sdk.BeaconManager.RangingListener({
onBeaconsDiscovered: function(region, list){
var beacons = [];
for (var index = 0; index < list.size(); index++){
var beacon = list.get(index);
beacons.push({
proximityUUID : beacon.getProximityUUID().toString(),
rssi : beacon.getRssi(),
major: beacon.getMajor(),
minor: beacon.getMinor(),
measuredPower: beacon.getMeasuredPower()
});
this.beaconManager.setRangingListener(new com.estimote.sdk.BeaconManager.RangingListener({
onBeaconsDiscovered: function(region, list){
var beacons = [];
for (var index = 0; index < list.size(); index++){
var beacon = list.get(index);
beacons.push({
proximityUUID : beacon.getProximityUUID().toString(),
rssi : beacon.getRssi(),
major: beacon.getMajor(),
minor: beacon.getMinor(),
measuredPower: beacon.getMeasuredPower(),
proximity: com.estimote.sdk.Utils.computeAccuracy(beacon)
});
}
_this.callback(beacons);
}
_this.callback(beacons);
}
}));
}
}));
}

Estimote.prototype.startRanging = function(data){
var _this = this;
com.estimote.sdk.SystemRequirementsChecker.check(this.context, new com.estimote.sdk.SystemRequirementsChecker.Callback({
onRequirementsMissing: function(requirements){
console.log("Missing perssion(s) " + requirements);
Estimote.prototype.startRanging = function(data){
var _this = this;
com.estimote.sdk.SystemRequirementsChecker.check(this.context, new com.estimote.sdk.SystemRequirementsChecker.Callback({
onRequirementsMissing: function(requirements){
console.log("Missing perssion(s) " + requirements);
}
}));
}));

_this.beaconManager.connect(new com.estimote.sdk.BeaconManager.ServiceReadyCallback({
onServiceReady : function(){
try {
_this.beaconManager.startRanging(_this.region);
}catch(error){
console.log(error.message);
}
}
}));
};
_this.beaconManager.connect(new com.estimote.sdk.BeaconManager.ServiceReadyCallback({
onServiceReady : function(){
try {
_this.beaconManager.startRanging(_this.region);
}catch(error){
console.log(error.message);
}
}
}));
};

Estimote.prototype.stopRanging = function(){
if (this.beaconManager != null) {
this.beaconManager.stopRanging(this.region);
}
};
Estimote.prototype.stopRanging = function(){
if (this.beaconManager != null) {
this.beaconManager.stopRanging(this.region);
}
};

return Estimote;
return Estimote;

})();

Expand Down
10 changes: 0 additions & 10 deletions Plugin/platforms/android/AndroidManifest.xml

This file was deleted.

9 changes: 8 additions & 1 deletion Plugin/platforms/android/include.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
android {
productFlavors {
"my-plugin" {
dimension "my-plugin"
}
}
}
dependencies {
compile 'com.estimote:sdk:0.9.4@aar'
}
}