본문 바로가기

블루투스3

안드로이드 BLE 통신(공식문서 번역) 3 BLE Characteristics 정보 읽기 일단 GATT 서버에 앱이 연결되어 서비스를 찾으면, attributes를 읽을 수 있다. 스니펫에서는 서버의 서비스들과 characters를 순회하고 UI에 띄운다. public class DeviceControlActivity extends Activity { ... // Demonstrates how to iterate through the supported GATT // Services/Characteristics. // In this sample, we populate the data structure that is bound to the // ExpandableListView on the UI. private void displayGattServi.. 2023. 7. 23.
안드로이드 BLE 통신(공식문서 번역) 2 GATT callback 선언 일단 서비스가 기기에 연결되면 BluetoothGattCallback을 통해 연결 상태에 대한 알림을 받는다. 서비스 회복, Characters read, Characters notifications onConnectionStateChanged 메소드는 디바이스의 GATT 서버 연결이 변경되었을 때 호출된다. 서비스 클래스에 선언되어 bluetoothAdapter 와 함께 사용될 수 있다. (서비스와 연결된 이후에) private final BluetoothGattCallback bluetoothGattCallback = new BluetoothGattCallback() { @Override public void onConnectionStateChange(BluetoothG.. 2023. 7. 23.
안드로이드 BLE 통신(공식문서 번역) 1 작성: 2023년 7월 21일 https://developer.android.com/guide/topics/connectivity/bluetooth/ble-overview 일반적인 블루투스과 다르게 저전력 사용을 목적으로 한다. 예) 접근 센서, 심장 맥박 측정기, 피트니스 디바이스 등 BLE 필요 권한(manifest) https://developer.android.com/guide/topics/connectivity/bluetooth/permissions#java 블루투스 지원 여부 확인 boolean bluetoothAvailable = getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH); 블루투스 BLE 여부 확인 bool.. 2023. 7. 23.