'bluetoothadapterlescancallback'에 해당되는 글 1건

  1. 2020.11.20 Android advertising 데이터 수신
Android2020. 11. 20. 14:31

 

 

 

BLE 4.0 에서 페어링 모드 외에 Advertising 모드가 있다. 

Advertising 데이터를 수신할때 이용한 간단한 콜백 코드이다.

BluetoothAdapter를 이용한다.

scanRecord 변수에 광고 데이터가 담겨오는데, 프로젝트 진행할때 62바이트씩 데이터가 들어왔었다.

안드로이드 내부적으로 scanRequest 를 진행해서 31바이트를 받고 31바이트를 더 요청해서, 

2개의 데이터 패킷을 합쳐서 올려주는것으로 판단되었다.

rssi는 신호 세기이며, BluetoothDevice 객체를 통해 기기의 Mac 주소 등 정보를 가져올 수 있다.

블루투스 켜져있는지 확인 등 메소드는 생략!

 

 private BluetoothAdapter.LeScanCallback mLeScanCallback = new BluetoothAdapter.LeScanCallback() {
        @Override
        public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) {
            Log.e("advertisement", "onLeScan = " + device.getAddress() + " scanRecord = " + Utils.byteArrayToHex(scanRecord));
        }
    };
Posted by 사슴영혼'-'