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 1fd0aa8186..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
@@ -9,7 +9,14 @@ android {
targetSdkVersion 22
versionCode 1
versionName "1.0"
+
+ }
+ repositories {
+ maven {
+ url "https://dl.bintray.com/alt236/maven"
+ }
}
+
buildTypes {
release {
minifyEnabled false
@@ -28,13 +35,22 @@ android {
packagingOptions {
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
+ exclude 'META-INF/DEPENDENCIES'
+ exclude 'META-INF/NOTICE'
+ exclude 'META-INF/LICENSE'
+ exclude 'META-INF/LICENSE.txt'
+ exclude 'META-INF/NOTICE.txt'
}
productFlavors {
}
+ compileOptions {
+ sourceCompatibility JavaVersion.VERSION_1_7
+ targetCompatibility JavaVersion.VERSION_1_7
+ }
}
dependencies {
- compile fileTree(dir: 'libs', include: ['*.jar'])
+ compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.2.1'
compile 'com.android.support:design:22.2.1'
compile 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.0.2'
@@ -42,5 +58,8 @@ dependencies {
compile 'commons-codec:commons-codec:1.4'
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 b7996fbd5c..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
@@ -13,6 +13,10 @@
+
+
+
+
+
+
+
+
+
+
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
new file mode 100755
index 0000000000..61e84c6809
--- /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/beacon/BeaconDetactorService.java
@@ -0,0 +1,131 @@
+/*
+ * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you 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.beacon;
+
+import android.app.NotificationManager;
+import android.app.PendingIntent;
+import android.app.Service;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Handler;
+import android.os.IBinder;
+import android.os.RemoteException;
+import android.support.v4.app.NotificationCompat;
+import android.util.Log;
+import agent.sense.android.iot.carbon.wso2.org.wso2_senseagent.R;
+
+import org.altbeacon.beacon.BeaconConsumer;
+import org.altbeacon.beacon.BeaconManager;
+import org.altbeacon.beacon.MonitorNotifier;
+import org.altbeacon.beacon.Region;
+
+public class BeaconDetactorService extends Service implements BeaconConsumer {
+
+ private BeaconManager iBeaconManager = BeaconManager.getInstanceForApplication(this);
+
+ @Override
+ public IBinder onBind(Intent arg0) {
+ return null;
+ }
+
+ @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();
+
+
+ final Handler handler = new Handler();
+ final Runnable runnable = new Runnable() {
+
+ @Override
+ public void run() {
+ //stopSelf();
+ }
+ };
+ handler.postDelayed(runnable, 10000);
+ }
+
+ @Override
+ public void onDestroy() {
+ iBeaconManager.unbind(this);
+ super.onDestroy();
+ }
+
+ @Override
+ public void onBeaconServiceConnect() {
+ iBeaconManager.setMonitorNotifier(new MonitorNotifier() {
+ @Override
+ public void didEnterRegion(Region region) {
+ Log.e("BeaconDetactorService", "didEnterRegion");
+ generateNotification(BeaconDetactorService.this, region.getUniqueId()
+ + ": just saw this iBeacon for the first time");
+ }
+
+ @Override
+ public void didExitRegion(Region region) {
+ Log.e("BeaconDetactorService", "didExitRegion");
+ generateNotification(BeaconDetactorService.this, region.getUniqueId() + ": is no longer visible");
+ }
+
+ @Override
+ public void didDetermineStateForRegion(int state, Region region) {
+ Log.e("BeaconDetactorService", "didDetermineStateForRegion:" + state);
+ }
+
+ });
+
+ try {
+ iBeaconManager.startMonitoringBeaconsInRegion(new Region("myMonitoringUniqueId", null, null, null));
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
+
+ }
+
+ /**
+ * Issues a notification to inform the user that server has sent a message.
+ */
+ private static void generateNotification(Context context, String message) {
+
+ Intent launchIntent = new Intent(context, MonitoringActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
+ | Intent.FLAG_ACTIVITY_SINGLE_TOP);
+
+ ((NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE)).notify(
+ 0,
+ new NotificationCompat.Builder(context).setWhen(System.currentTimeMillis())
+ .setSmallIcon(R.drawable.beacon).setTicker(message)
+ .setContentTitle(context.getString(R.string.app_name)).setContentText(message)
+ .setContentIntent(PendingIntent.getActivity(context, 0, launchIntent, 0)).setAutoCancel(true)
+ .build());
+
+ }
+
+}
\ No newline at end of file
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/BeaconScanedData.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/BeaconScanedData.java
new file mode 100644
index 0000000000..e33e3f8e2c
--- /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/beacon/BeaconScanedData.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you 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.beacon;
+
+import java.util.Date;
+
+
+public class BeaconScanedData {
+
+
+ private int beaconMajor;// Major
+ private int beaconMinor;//Minor
+ private String beaconProximity;// Proximity
+ private int beaconUuid;// Uuid
+ private long timestamp;// Timestamp
+
+ BeaconScanedData(int beaconMajor, int beaconMinor,String beaconProximity,int beaconUuid) {
+ this.beaconMajor = beaconMajor;
+ this.beaconMinor = beaconMinor;
+ this.beaconProximity = beaconProximity;
+ this.beaconUuid = beaconUuid;
+ timestamp = new Date().getTime();
+
+ }
+
+ public int getBeaconMajor() {
+ return beaconMajor;
+ }
+
+ public void setBeaconMajor(int beaconMajor) {
+ this.beaconMajor = beaconMajor;
+ }
+
+ public int getBeaconMinor() {
+ return beaconMinor;
+ }
+
+ public void setBeaconMinor(int beaconMinor) {
+ this.beaconMinor = beaconMinor;
+ }
+
+ public String getBeaconProximity() {
+ return beaconProximity;
+ }
+
+ public void setBeaconProximity(String beaconProximity) {
+ this.beaconProximity = beaconProximity;
+ }
+
+ public int getBeaconUuid() {
+ return beaconUuid;
+ }
+
+ public void setBeaconUuid(int beaconUuid) {
+ this.beaconUuid = beaconUuid;
+ }
+
+ public long getTimeStamp() {
+ return timestamp;
+ }
+
+ public void setTimeStamp(long timeStamp) {
+ timestamp = timeStamp;
+ }
+}
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/BeaconServiceUtility.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/BeaconServiceUtility.java
new file mode 100755
index 0000000000..1a4271b5e2
--- /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/beacon/BeaconServiceUtility.java
@@ -0,0 +1,71 @@
+package org.wso2.carbon.iot.android.sense.beacon;
+
+import java.util.Calendar;
+
+import android.app.AlarmManager;
+import android.app.PendingIntent;
+import android.content.Context;
+import android.content.Intent;
+import org.altbeacon.beacon.BeaconConsumer;
+import org.altbeacon.beacon.BeaconManager;
+/*
+ * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 Inc. licenses this file to you 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.
+ */
+public class BeaconServiceUtility {
+
+ private Context context;
+ private PendingIntent pintent;
+ private AlarmManager alarm;
+ private Intent iService;
+
+ public BeaconServiceUtility(Context context) {
+ super();
+ this.context = context;
+ iService = new Intent(context, BeaconDetactorService.class);
+ alarm = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
+ pintent = PendingIntent.getService(context, 0, iService, 0);
+ }
+
+ public void onStart(BeaconManager iBeaconManager, BeaconConsumer consumer) {
+
+ stopBackgroundScan();
+ iBeaconManager.bind(consumer);
+
+ }
+
+ public void onStop(BeaconManager iBeaconManager, BeaconConsumer consumer) {
+
+ iBeaconManager.unbind(consumer);
+ startBackgroundScan();
+
+ }
+
+ private void stopBackgroundScan() {
+
+ alarm.cancel(pintent);
+ context.stopService(iService);
+ }
+
+ private void startBackgroundScan() {
+
+ Calendar cal = Calendar.getInstance();
+ cal.add(Calendar.SECOND, 2);
+ alarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 360000, pintent); // 6*60 * 1000
+ context.startService(iService);
+ }
+
+}
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/MonitoringActivity.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/MonitoringActivity.java
new file mode 100644
index 0000000000..5b24c38587
--- /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/beacon/MonitoringActivity.java
@@ -0,0 +1,252 @@
+/*
+ * 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.beacon;
+
+
+import android.Manifest;
+import android.annotation.TargetApi;
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.os.Build;
+import android.os.Bundle;
+import android.os.RemoteException;
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.util.Log;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.EditText;
+import android.view.LayoutInflater;
+import android.widget.BaseAdapter;
+import org.altbeacon.beacon.BeaconConsumer;
+import org.altbeacon.beacon.BeaconManager;
+import org.altbeacon.beacon.Beacon;
+import org.altbeacon.beacon.RangeNotifier;
+import android.widget.ListView;
+import android.widget.TextView;
+import org.altbeacon.beacon.BeaconParser;
+import org.altbeacon.beacon.MonitorNotifier;
+import org.altbeacon.beacon.Region;
+import org.wso2.carbon.iot.android.sense.beacon.BeaconScanedData;
+import org.wso2.carbon.iot.android.sense.util.SenseDataHolder;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.logging.Handler;
+import agent.sense.android.iot.carbon.wso2.org.wso2_senseagent.R;
+
+public class MonitoringActivity extends Activity implements BeaconConsumer {
+ protected static final String TAG = MonitoringActivity.class.getName();
+ private static final int PERMISSION_REQUEST_COARSE_LOCATION = 1;
+ private ListView list = null;
+ private BeaconAdapter adapter;
+ private ArrayList arrayL = new ArrayList<>();
+ private LayoutInflater inflater;
+
+ private BeaconServiceUtility beaconUtill = null;
+ private BeaconManager iBeaconManager = BeaconManager.getInstanceForApplication(this);
+
+ BeaconScanedData beaconData;
+
+ @Override
+ public void onBeaconServiceConnect() {
+
+ iBeaconManager.setBackgroundMode(true);
+
+
+ iBeaconManager.setRangeNotifier(new RangeNotifier() {
+ @Override
+ public void didRangeBeaconsInRegion(Collection iBeacons, Region region) {
+ for (Beacon beacon: iBeacons) {
+ Log.i(TAG, "This beacon has identifiers:"+beacon.getId1()+", "+beacon.getId2()+", "+beacon.getId3());
+
+
+ }
+
+ arrayL.clear();
+ arrayL.addAll(iBeacons);
+ //adapter.notifyDataSetChanged();
+ }
+
+ });
+
+ iBeaconManager.setMonitorNotifier(new MonitorNotifier() {
+ @Override
+ public void didEnterRegion(Region region) {
+ Log.e("BeaconDetactorService", "didEnterRegion");
+ // logStatus("I just saw an iBeacon for the first time!");
+ }
+
+ @Override
+ public void didExitRegion(Region region) {
+ Log.e("BeaconDetactorService", "didExitRegion");
+ // logStatus("I no longer see an iBeacon");
+ }
+
+ @Override
+ public void didDetermineStateForRegion(int state, Region region) {
+ Log.e("BeaconDetactorService", "didDetermineStateForRegion");
+ // logStatus("I have just switched from seeing/not seeing iBeacons: " + state);
+ }
+
+ });
+
+ try {
+ iBeaconManager.startRangingBeaconsInRegion(new Region("myRangingUniqueId", null, null, null));
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
+
+ try {
+ iBeaconManager.startMonitoringBeaconsInRegion(new Region("myMonitoringUniqueId", null, null, null));
+ } catch (RemoteException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_monitor);
+ beaconUtill = new BeaconServiceUtility(this);
+ list = (ListView) findViewById(R.id.list);
+ adapter = new BeaconAdapter();
+ list.setAdapter(adapter);
+ inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
+
+ //iBeaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25"));
+ iBeaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
+
+ iBeaconManager.bind(this);
+
+ iBeaconManager.setRangeNotifier(new RangeNotifier() {
+ @Override
+ public void didRangeBeaconsInRegion(Collection beacons, Region region) {
+ for(Beacon beacon : beacons) {
+ Log.d(TAG, "UUID:" + beacon.getId1() + ", major:" + beacon.getId2() + ", minor:" + beacon.getId3() + ", Distance:" + beacon.getDistance() + ",RSSI" + beacon.getRssi() + ", TxPower" + beacon.getTxPower());
+ }
+ arrayL.clear();
+ arrayL.addAll(beacons);
+ }
+ });
+
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ }
+
+ @Override
+ protected void onStart() {
+ super.onStart();
+ beaconUtill.onStart(iBeaconManager, this);
+ beaconUtill = new BeaconServiceUtility(this);
+ }
+
+ @Override
+ protected void onStop() {
+ beaconUtill.onStop(iBeaconManager, this);
+ super.onStop();
+ }
+
+
+ private class BeaconAdapter extends BaseAdapter {
+
+ @Override
+ public int getCount() {
+ if (arrayL != null && arrayL.size() > 0)
+ return arrayL.size();
+ else
+ return 0;
+ }
+
+ @Override
+ public Beacon getItem(int arg0) {
+ return arrayL.get(arg0);
+ }
+
+ @Override
+ public long getItemId(int arg0) {
+ return arg0;
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ try {
+ ViewHolder holder;
+
+ if (convertView != null) {
+ holder = (ViewHolder) convertView.getTag();
+ } else {
+ holder = new ViewHolder(convertView = inflater.inflate(R.layout.tupple_monitoring, null));
+ }
+ holder.beacon_uuid.setText("UUID: " + arrayL.get(position).getId1().toString().toUpperCase());
+
+ holder.beacon_major.setText("Major: " + arrayL.get(position).getId2());
+
+ holder.beacon_minor.setText(" Minor: " + arrayL.get(position).getId3());
+
+ double proximity = arrayL.get(position).getDistance();
+ holder.beacon_proximity.setText("Proximity: " + (new BigDecimal(proximity).setScale(5, BigDecimal.ROUND_HALF_UP).doubleValue()));
+
+ holder.beacon_rssi.setText(" Rssi: " + arrayL.get(position).getRssi());
+
+ holder.beacon_txpower.setText(" TxPower: " + arrayL.get(position).getTxPower());
+
+ holder.beacon_range.setText("" + arrayL.get(position).getDistance());
+
+ beaconData = new BeaconScanedData(arrayL.get(position).getId2().toInt(), arrayL.get(position).getId3().toInt(),holder.beacon_uuid.toString(),arrayL.get(position).getRssi());
+ SenseDataHolder.getBeaconScanedDataHolder().add(beaconData);
+
+
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return convertView;
+ }
+
+ private class ViewHolder {
+ private TextView beacon_uuid;
+ private TextView beacon_major;
+ private TextView beacon_minor;
+ private TextView beacon_proximity;
+ private TextView beacon_rssi;
+ private TextView beacon_txpower;
+ private TextView beacon_range;
+
+
+ public ViewHolder(View view) {
+ beacon_uuid = (TextView) view.findViewById(R.id.BEACON_uuid);
+ beacon_major = (TextView) view.findViewById(R.id.BEACON_major);
+ beacon_minor = (TextView) view.findViewById(R.id.BEACON_minor);
+ beacon_proximity = (TextView) view.findViewById(R.id.BEACON_proximity);
+ beacon_rssi = (TextView) view.findViewById(R.id.BEACON_rssi);
+ beacon_txpower = (TextView) view.findViewById(R.id.BEACON_txpower);
+ beacon_range = (TextView) view.findViewById(R.id.BEACON_range);
+
+
+ view.setTag(this);
+ }
+ }
+
+ }
+
+}
\ No newline at end of file
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