diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/build.gradle b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/build.gradle
index 3c6c7507fe..bf9860dba5 100755
--- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/build.gradle
+++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/build.gradle
@@ -11,6 +11,12 @@ android {
versionName "1.0"
}
+ repositories {
+ maven {
+ url "https://dl.bintray.com/alt236/maven"
+ }
+ }
+
buildTypes {
release {
minifyEnabled false
@@ -53,5 +59,7 @@ dependencies {
compile 'com.netflix.feign:feign-jaxrs:8.16.0'
compile 'com.netflix.feign:feign-jackson:8.16.0'
compile 'org.altbeacon:android-beacon-library:2.8.1'
+ compile 'uk.co.alt236:easycursor-android:1.0.0'
+ compile 'uk.co.alt236:bluetooth-le-library-android:1.0.0'
}
diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/AndroidManifest.xml b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/AndroidManifest.xml
index d1857e4364..7ba9b334cc 100755
--- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/AndroidManifest.xml
+++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/AndroidManifest.xml
@@ -78,6 +78,12 @@
android:label="Beacon Monitor"
android:theme="@style/AppTheme.NoActionBar" >
+
+
+
diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/beacon/BeaconDetactorService.java b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/beacon/BeaconDetactorService.java
index c3c66a52ba..61e84c6809 100755
--- a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/beacon/BeaconDetactorService.java
+++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/beacon/BeaconDetactorService.java
@@ -45,20 +45,29 @@ public class BeaconDetactorService extends Service implements BeaconConsumer {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
+
+ new Thread(){
+ @Override
+ public void run() {
+ iBeaconManager.bind(BeaconDetactorService.this);
+ }
+ }.start();
+
+
return START_STICKY;
}
@Override
public void onCreate() {
super.onCreate();
- iBeaconManager.bind(this);
+
final Handler handler = new Handler();
final Runnable runnable = new Runnable() {
@Override
public void run() {
- stopSelf();
+ //stopSelf();
}
};
handler.postDelayed(runnable, 10000);
diff --git a/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/bmonitor/BeaconMonitoringActivity.java b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/bmonitor/BeaconMonitoringActivity.java
new file mode 100644
index 0000000000..23785db26a
--- /dev/null
+++ b/components/iot-plugins/androidsense-plugin/org.wso2.carbon.device.mgt.iot.androidsense.agent/app/src/main/java/org/wso2/carbon/iot/android/sense/bmonitor/BeaconMonitoringActivity.java
@@ -0,0 +1,121 @@
+/*
+ *
+ * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.wso2.carbon.iot.android.sense.bmonitor;
+
+import android.annotation.TargetApi;
+import android.app.Activity;
+import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothDevice;
+import android.os.AsyncTask;
+import android.os.Build;
+import android.os.Bundle;
+import android.support.v7.app.AppCompatActivity;
+import android.widget.ListView;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import agent.sense.android.iot.carbon.wso2.org.wso2_senseagent.R;
+import uk.co.alt236.bluetoothlelib.device.BluetoothLeDevice;
+import uk.co.alt236.easycursor.objectcursor.EasyObjectCursor;
+
+public class BeaconMonitoringActivity extends AppCompatActivity {
+
+ private BluetoothLeScanner mScanner;
+ private BluetoothUtils mBluetoothUtils;
+ private LeDeviceListAdapter mLeDeviceListAdapter;
+ private BluetoothLeDeviceStore mDeviceStore;
+
+ protected ListView mList;
+
+ public static final int MINIMUM_DISTANCE = -70;
+
+ public static Map itemMap;
+
+ @TargetApi(Build.VERSION_CODES.LOLLIPOP)
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_beacon_monitoring);
+
+ itemMap = new HashMap();
+ itemMap.put("DC:5F:BD:68:88:D5", "Noodles");
+ itemMap.put("EF:0F:50:D5:BA:A1", "Vegetables");
+ itemMap.put("FA:F2:CF:84:C2:F7", "Oil");
+
+ mList = (ListView) this.findViewById(android.R.id.list);
+
+ mDeviceStore = new BluetoothLeDeviceStore();
+ mBluetoothUtils = new BluetoothUtils(this);
+ mScanner = new BluetoothLeScanner(mLeScanCallback, mBluetoothUtils);
+ startScan();
+ }
+
+ private final BluetoothAdapter.LeScanCallback mLeScanCallback = new BluetoothAdapter.LeScanCallback() {
+ @Override
+ public void onLeScan(final BluetoothDevice device, final int rssi, final byte[] scanRecord) {
+ final BluetoothLeDevice deviceLe = new BluetoothLeDevice(device, rssi, scanRecord, System.currentTimeMillis());
+ if(deviceLe!= null && deviceLe.getName()!= null && !deviceLe.getName().equals("Unknown Device")){
+ mDeviceStore.addDevice(deviceLe);
+
+ if(deviceLe.getRssi() > MINIMUM_DISTANCE){
+ Object[] objects = new Object[4];
+ objects[0] = deviceLe.getName();
+ objects[1] = deviceLe.getAddress();
+ objects[2] = deviceLe.getRssi();
+ objects[3] = itemMap.get(device.getAddress());
+
+ new SendToSiddi().execute(objects);
+ }
+
+
+ final EasyObjectCursor c = mDeviceStore.getDeviceCursor();
+ runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ mLeDeviceListAdapter.swapCursor(c);
+ }
+ });
+ }
+ }
+ };
+
+ private void startScan() {
+
+ mLeDeviceListAdapter = new LeDeviceListAdapter(this, mDeviceStore.getDeviceCursor());
+ mList.setAdapter(mLeDeviceListAdapter);
+
+ final boolean mIsBluetoothOn = mBluetoothUtils.isBluetoothOn();
+ final boolean mIsBluetoothLePresent = mBluetoothUtils.isBluetoothLeSupported();
+ mBluetoothUtils.askUserToEnableBluetoothIfNeeded();
+ if (mIsBluetoothOn && mIsBluetoothLePresent) {
+ mScanner.scanLeDevice(-1, true);
+ invalidateOptionsMenu();
+ }
+ }
+
+
+ public class SendToSiddi extends AsyncTask