내 프로젝트에 android.bluetooth 패키지를 사용했지만 읽기 및 쓰기 특성을 위해 IBluetoothGatt를 구현하려고합니다. 하지만 난 IBluetoothGatt 인터페이스Android 블루투스 저에너지 갓 서비스 구현 오류
public final class BluetoothGatt implements BluetoothProfile {
private static final String TAG = "BluetoothGatt";
private static final boolean DBG = true;
private static final boolean VDBG = false;
private IBluetoothGatt mService; // IBluetoothGatt red highlights. Some functions in IBluetoothGatt interface just work by put breakpoints.
private BluetoothGattCallback mCallback;
private int mClientIf;
private boolean mAuthRetry = false;
private BluetoothDevice mDevice;
private boolean mAutoConnect;
private int mConnState;
private final Object mStateLock = new Object();
private Boolean mDeviceBusy = false;
private int mTransport;
private static final int CONN_STATE_IDLE = 0;
private static final int CONN_STATE_CONNECTING = 1;
private static final int CONN_STATE_CONNECTED = 2;
private static final int CONN_STATE_DISCONNECTING = 3;
private static final int CONN_STATE_CLOSED = 4;
private List<BluetoothGattService> mServices;
writeCharacteristic 빨간색 하이라이트 아래
public void onCharacteristicWrite(String address, int status, int handle) {
if (VDBG) Log.d(TAG, "onCharacteristicWrite() - Device=" + address
+ " handle=" + handle + " Status=" + status);
if (!address.equals(mDevice.getAddress())) {
return;
}
synchronized(mDeviceBusy) {
mDeviceBusy = false;
}
BluetoothGattCharacteristic characteristic = getCharacteristicById(mDevice, handle);
if (characteristic == null) return;
if ((status == GATT_INSUFFICIENT_AUTHENTICATION
|| status == GATT_INSUFFICIENT_ENCRYPTION)
&& mAuthRetry == false) {
try {
mAuthRetry = true;
mService.writeCharacteristic(mClientIf, address, handle,
characteristic.getWriteType(), AUTHENTICATION_MITM,
characteristic.getValue());
return;
} catch (RemoteException e) {
Log.e(TAG,"",e);
}
}
정확히 무엇을하고 싶으신가요? –
쓰기 기능을 사용하여 수신 장치와 통신하고 싶습니다. 그러나 Ibluetoothgatt 인터페이스의 writeCharacteristic 메소드 (android.bluetooth)는 "해결할 수 없습니다"라고 할 수는 없습니다. – Hilal
코드를 편집하고 전체 활동 및 서비스 코드를 작성하십시오. 데이터를 쓰기 전에 장치를 스캔하여 연결해야합니다. –