Created
May 7, 2015 09:32
-
-
Save yankeppey/d14e0e2e1ae59b771f32 to your computer and use it in GitHub Desktop.
Kontakt.io beacon layout for AltBeacon library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MainActivity extends Activity implements BeaconConsumer { | |
protected static final String TAG = "RangingActivity"; | |
BeaconManager beaconManager = BeaconManager.getInstanceForApplication(this); | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
beaconManager.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25")); | |
beaconManager.bind(this); | |
} | |
@Override | |
public void onBeaconServiceConnect() { | |
beaconManager.setRangeNotifier(new RangeNotifier() { | |
@Override | |
public void didRangeBeaconsInRegion(Collection<Beacon> beacons, Region region) { | |
if (beacons.size() > 0) { | |
Log.d(TAG, "The first beacon I see is about "+beacons.iterator().next().getDistance()+" meters away."); | |
} | |
} | |
}); | |
try { | |
beaconManager.startRangingBeaconsInRegion(new Region("myRangingUniqueId", null, null, null)); | |
} catch (RemoteException e) { } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment