私のプロジェクトでは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);
}
}
あなたがしたいことを正確にしてください –
私は書き込み特性のメソッドでbleデバイスと通信したいです。しかし、Ibluetoothのインターフェース(android.bluetooth)のwriteCharacteristicメソッドは "解決できません"と私はこれを行うことはできません。 – Hilal
あなたのコードを編集し、活動とサービスの全コードを書いてください。 データを書き込む前にデバイスをスキャンして接続する必要があります。 –