0

내 프로젝트에 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); 
       } 
      } 
+1

정확히 무엇을하고 싶으신가요? –

+0

쓰기 기능을 사용하여 수신 장치와 통신하고 싶습니다. 그러나 Ibluetoothgatt 인터페이스의 writeCharacteristic 메소드 (android.bluetooth)는 "해결할 수 없습니다"라고 할 수는 없습니다. – Hilal

+0

코드를 편집하고 전체 활동 및 서비스 코드를 작성하십시오. 데이터를 쓰기 전에 장치를 스캔하여 연결해야합니다. –

답변

0

사용 그것으로이 문서는 매우 유용과 같은 몇 가지 문제가있다. BLE

코멘트 당신이 어떤 문제가 여기에

에게있는 경우는 상상력 장치에 연결하는 코드이다.

public boolean connect(final String address) 
{ 

    if (mBluetoothAdapter == null || address == null) 
    { 
     Log.e(TAG, "BluetoothAdapter not initialized or unspecified address."); 
     return false; 
    } 
    final BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address); 
    if (device == null) 
    { 
     Log.e(TAG, "Device not found. Unable to connect."); 
     return false; 
    } 
    // We want to directly connect to the device, so we are setting the autoConnect 
    // parameter to false. 
    mBluetoothGatt = device.connectGatt(this, false, mGattCallback); 

    return true; 
} 
+0

나는 당신의 제안 장치를 연결하려고 시도했지만 정의 IBluetoothGatt (적색)처럼 BluetothGatt.java에서 동일한 오류가 발생했다. clientConnect는 IBluetoothGattCallback 메서드에서 빨간색이고 장치에 아무 것도 쓸 수 없다. – Hilal

+0

IBluetoothGatt는 Android에 내장되어 있으며 공개 API의 일부가 아닙니다. 따라서 IDE에서이 파일을 열지 마십시오. BluetoothGatt는 IDE에서 열어야하는 파일이 아닙니다. 프로젝트를 컴파일 할 수 없다면 SDK 설정을 다시 한 번 살펴 봐야합니다. – Emil

관련 문제