0

私のプロジェクトではandroid.bluetoothパッケージを使用しましたが、読み書き特性のためにIBluetoothGattを実装しようとしています。しかし、私はIBluetoothGattインターフェイスでAndroid Bluetooth Low energy Gattサービス実装エラー

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

私は書き込み特性のメソッドでbleデバイスと通信したいです。しかし、Ibluetoothのインターフェース(android.bluetooth)のwriteCharacteristicメソッドは "解決できません"と私はこれを行うことはできません。 – Hilal

+0

あなたのコードを編集し、活動とサービスの全コードを書いてください。 データを書き込む前にデバイスをスキャンして接続する必要があります。 –

答えて

0

使用それによって、この記事は非常に便利であるようないくつかの問題を抱えています。 BLE

コメントあなたはすべての問題

を持っている場合、ここで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.javaと同じエラーがIBluetoothGatt(赤色)の定義と同じですが、clientConnectは赤色のIBluetoothGattCallbackメソッドであり、何もデバイスに書き込めません。 – Hilal

+0

IBluetoothGattはAndroidに内蔵されており、パブリックAPIの一部ではありません。したがって、このファイルをIDEで開くべきではありません。 BluetoothGattはIDEで開くべきファイルでもありません。プロジェクトをコンパイルできない場合は、SDKの設定をもう一度見てください。 – Emil

関連する問題