2017-03-02 7 views
2

BLE 4.2 장치에서 사용자 지정 특성을 사용하여 사용자 지정 서비스를 실행하고 있습니다. 나는 특성을 읽고 쓰기 위해 안드로이드 애플 리케이션에서 일하고있다. 내가 먼저 시도하는 것은 특성을 읽는 것이다.Android BLE Service 누락 된 특성

나는 UUID 목록을 정의합니다 : List chars = new ArrayList <>();

내가 아는 서비스 UUID를 사용하여 서비스를 만듭니다. mCustomService = mBluetoothGatt.getService (MY_SERVICE_UUID);

chars.clear(); 
chars.add(UUID1); 
chars.add(UUID2); 
chars.add(UUID3); 
chars.add(UUID4); 

I read the first characteristic from the end of my list: 
BluetoothGattCharacteristic mReadCharacteristic = mCustomService.getCharacteristic(chars.get(chars.size() - 1)); 
    if(mReadCharacteristic != null) 
     mBluetoothGatt.readCharacteristic(mReadCharacteristic); 

mReadCharacteristic는 항상 null을 반환

서비스 내 특성을 포함하지 않는 : 4 내 서비스에서 UUID를 알고 함께

나는 목록을로드합니다.

BLE "스니퍼"앱을 사용하면 모든 특성을 볼 수 있습니다.

감사

리치

PS 내가 여기에 서식을 알아낼 수 없습니다!

답변

0

나는 장치가 BLE 4.0이더라도 맞춤식 서비스와 특성을 갖춘 장치를 가지고 있습니다. 앱에, 아마 당신은이 일을하고 있지만 질문에 그것을 언급하지 않습니다 -하지만 당신은 다음 콜백 onServicesDiscovered을 트리거합니다

mBluetoothGatt.discoverServices();

을 요구하고있다. onServicesDiscovered 처리기 내부에서 비슷한 코드를 가지고 있으며 정상적으로 작동합니다.

public void onServicesDiscovered(BluetoothGatt gatt, int status) { if (status == BluetoothGatt.GATT_SUCCESS) { // getService // getCharactistics } // etc. }