bluno basic memo의 안드로이드 프로그램을 분석하여 한번 연결되었던 것은 자동으로 다시 연결되게 하려고 합니다. (원래 // Previously connected device. Try to reconnect 코드는 주석이였음)
주석을 풀고도 안되는데 조건문이
if (mBluetoothDeviceAddress != null && address.equals(mBluetoothDeviceAddress) && mBluetoothGatt != null)
입니다.
09-24 02:21:54.695 30502-30502/ after before address D0:39:72:C4:DE:2B null (연결 전)
09-24 02:21:54.705 30502-30502/ before address D0:39:72:C4:DE:2B android.bluetooth.BluetoothGatt@423b8c98 (바로 연결 직후)
09-24 02:21:58.905 30502-30502 after address D0:39:72:C4:DE:2B android.bluetooth.BluetoothGatt@423e5230
--------------------------
연결 끊고 재 연결시도
-------------------------
09-24 02:21:58.895 30502-30502 before address D0:39:72:C4:DE:2B null ( BluetoothGatt = NULL이 됨)
한번 연결 후 재 연결을 시도할 때 확인해보니까 mBluetoothDeviceAddress랑 address.equals은 NULL이 아닌데 mBluetoothGatt이 Null이라 연결이 되지 않습니다.
mBluetoothGatt이 의미하고 있는 것이 무엇인지 왜 초기화 되는지 궁금합니다
public boolean connect(final String address) {
System.out.println("BluetoothLeService connect"+address+mBluetoothGatt);
if (mBluetoothAdapter == null || address == null) {
Log.w(TAG, "BluetoothAdapter not initialized or unspecified address.");
return false;
}
// Previously connected device. Try to reconnect.
System.out.println("before address "+mBluetoothDeviceAddress +" "+ mBluetoothGatt);
if (mBluetoothDeviceAddress != null && address.equals(mBluetoothDeviceAddress)
&& mBluetoothGatt != null) {
Log.d(TAG, "Trying to use an existing mBluetoothGatt for connection.");
if (mBluetoothGatt.connect()) {
System.out.println("mBluetoothGatt connect");
mConnectionState = STATE_CONNECTING;
return true;
} else {
System.out.println("mBluetoothGatt else connect");
return false;
}
}
final BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(address);
if (device == null) {
Log.w(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.
System.out.println("device.connectGatt connect");
synchronized(this)
{
mBluetoothGatt = device.connectGatt(this, false, mGattCallback);
}
Log.d(TAG, "Trying to create a new connection.");
mBluetoothDeviceAddress = address;
System.out.println("after address "+mBluetoothDeviceAddress +" "+ mBluetoothGatt);
mConnectionState = STATE_CONNECTING;
return true;
}