AltBeacon의 라이브러리를 사용했습니다.
그래들 디펜던시에
compile 'org.altbeacon:android-beacon-library:2+'
부분을 추가했구요
메인 코드는 예제 코드와 똑같습니다.
public class MainActivity extends AppCompatActivity implements BeaconConsumer {
private BeaconManager bm;
private TextView tv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bm = BeaconManager.getInstanceForApplication(this);
tv = (TextView)findViewById(R.id.rssiText);
// bm.getBeaconParsers().add(new BeaconParser().setBeaconLayout("m:2-3=0418,i:4-13,i:14-23,p:24-24,d:25-25'"));
bm.bind(this);
}
@Override
protected void onDestroy() {
super.onDestroy();
bm.unbind(this);
}
@Override
public void onBeaconServiceConnect()
{
bm.setRangeNotifier(new RangeNotifier() {
@Override
public void didRangeBeaconsInRegion(Collection beacons, Region region) {
if (beacons.size() > 0) {
Log.i("log", "The first beacon I see is about "
+ ((Beacon) beacons.iterator().next()).getDistance() + " meters away.");
}
}
});
try
{
bm.startRangingBeaconsInRegion(new Region("myRegion", null, null, null));
}
catch (RemoteException e)
{
}
}
}
로그가 도저히 찍히질 않네요.
테스트 기종은 삼성 갤럭시 S6이고, OS는 5.1.1입니다.
비콘이 잘못된걸까요 ..?
사용한 비콘은 아이폰, 안드로이드 모두 지원하는 IBeacon입니다.
http://altbeacon.github.io/android-beacon-library/samples.html 의 샘플을 참고했습니다.