Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Christof Wolke
BIDL
Commits
0f27b8d6
Commit
0f27b8d6
authored
Jul 29, 2016
by
Christof Wolke
Browse files
getting the nearest Beacon
parent
8c532929
Changes
3
Hide whitespace changes
Inline
Side-by-side
BIDL/BIDL/app/src/main/AndroidManifest.xml
View file @
0f27b8d6
<?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"
...
...
BIDL/BIDL/app/src/main/java/de/uni_oldenburg/bidl/MainActivity.java
View file @
0f27b8d6
...
...
@@ -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
();
}
}
BIDL/BIDL/app/src/main/res/layout/activity_main.xml
View file @
0f27b8d6
...
...
@@ -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!"
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment