Commit 0f27b8d6 authored by Christof Wolke's avatar Christof Wolke

getting the nearest Beacon

parent 8c532929
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="de.uni_oldenburg.bidl">
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="de.uni_oldenburg.bidl">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
......
......@@ -2,15 +2,62 @@ package de.uni_oldenburg.bidl;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
import com.estimote.sdk.Beacon;
import com.estimote.sdk.BeaconManager;
import com.estimote.sdk.Region;
import com.estimote.sdk.SystemRequirementsChecker;
import java.util.List;
import java.util.UUID;
public class MainActivity extends AppCompatActivity {
private static final UUID ESTIMOTE_PROXIMITY_UUID = UUID.fromString("B9407F30-F5F8-466E-AFF9-25556B57FE6D");
private Region region;
private BeaconManager beaconManager;
private TextView beaconID;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
beaconID = (TextView) findViewById(R.id.BeaconID);
//Start ranging for beacons
beaconManager = new BeaconManager(this);
beaconManager.setRangingListener(new BeaconManager.RangingListener() {
@Override
public void onBeaconsDiscovered(Region region, List<Beacon> list) {
if (!list.isEmpty()){
Beacon nearestBeacon = list.get(0);
//// TODO: 29.07.2016 Servercall to get the Event, wich takes place.
showBeaconID(nearestBeacon);
}
}
});
region = new Region("ranged region", ESTIMOTE_PROXIMITY_UUID, null, null);
}
/**
* Only for Testing. Shows the BeaconIDs in the Textview with the ID = beaconID.
* @param nearestBeacon the nearest Beacon for the user
*/
//Todo delete the method
private void showBeaconID(Beacon nearestBeacon) {
beaconID.setText("UUID: "+nearestBeacon.getProximityUUID()+" \n" +
" minor: "+nearestBeacon.getMinor()+" \n" +
" major: "+nearestBeacon.getMajor());
}
@Override
......@@ -18,5 +65,24 @@ public class MainActivity extends AppCompatActivity {
super.onResume();
// is Bluetooth on, is Location on, etc.
SystemRequirementsChecker.checkWithDefaultDialogs(this);
// Start ranging for beacons, when the activity appears on the screen
beaconManager.connect(new BeaconManager.ServiceReadyCallback() {
@Override
public void onServiceReady() {
beaconManager.startRanging(region);
}
});
}
/**
* Ranging ist stopped, if the Activity disappears.
*/
@Override
public void onPause(){
beaconManager.stopRanging(region);
super.onPause();
}
}
......@@ -8,6 +8,7 @@
tools:context="de.uni_oldenburg.bidl.MainActivity">
<TextView
android:id="@+id/BeaconID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment