연결을 끊고 BLE 장치를 전화기에 연결하는 데 문제가 있습니다. 내 전화기에는 연결 해제 버튼이 있습니다. 전화기와 장치가 연결되면 장치를 눌러 연결을 끊습니다. 성공적으로 연결이 끊어졌습니다. 그러나 연결 함수를 호출하면 10 초 후에 다시 연결됩니다. 이것은 내 코드이고 logcat입니다. 재 연결 시간을 줄이는 데 도와 주시겠습니까? 클라이언트가 링크 계층 수준에 연결 요청을 보낼 때BLE에서 재 연결 시간을 수정하는 방법은 무엇입니까?
public boolean connect(final String address) {
if (mBluetoothAdapter == null || address == null) {
Log.w(TAG, "BluetoothAdapter not initialized or unspecified address.");
return false;
}
// Previously connected device. Try to reconnect.
if (mBluetoothDeviceAddress != null && address.equals(mBluetoothDeviceAddress)
&& mBluetoothGatt != null) {
Log.d(TAG, "Trying to use an existing mBluetoothGatt for connection.");
if (mBluetoothGatt.connect()) {
mConnectionState = STATE_CONNECTING;
return true;
} else {
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.
//mBluetoothGatt = device.connectGatt(this, true, mGattCallback);
new Handler(getMainLooper()).post(new Runnable() {
@Override
public void run() {
if (device != null) {
mBluetoothGatt = device.connectGatt(getApplicationContext(), true, mGattCallback);
}
}
});
}
이 내 로그 캣
10-27 23:19:37.284 13162-13162/com.example.blechat D/BluetoothGatt: close()
10-27 23:19:37.284 13162-13162/com.example.blechat D/BluetoothGatt: unregisterApp() - mClientIf=6
10-27 23:19:37.314 13162-13162/com.example.blechat D/BluetoothLeService: Trying to create a new connection.
10-27 23:19:37.354 13162-13162/com.example.blechat D/BluetoothGatt: connect() - device: 00:02:5B:00:15:33, auto: true
10-27 23:19:37.354 13162-13162/com.example.blechat D/BluetoothGatt: registerApp()
10-27 23:19:37.354 13162-13162/com.example.blechat D/BluetoothGatt: registerApp() - UUID=23513bb1-c4fc-4203-ad3a-d58c38f2ddfb
10-27 23:19:37.394 13162-13706/com.example.blechat D/BluetoothGatt: onClientRegistered() - status=0 clientIf=6
10-27 23:19:42.374 13162-13162/com.example.blechat D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
10-27 23:19:48.994 13162-13162/com.example.blechat D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
10-27 23:19:56.704 13162-13706/com.example.blechat D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=6 device=00:02:5B:00:15:33
감사합니다. 코드로 어떻게 수정할 수 있습니까? 이론뿐만 아니라 – Jame
말하기 어렵습니다. 일반적으로 BLE 장치에서 수행됩니다. 어떤 장치를 사용하고 있습니까? 장치의 BLE API에는 "Set Advertising Parameters"또는 "Set Advertising Interval"또는 이와 유사한 기능이 있어야합니다. 그러나이 전화가 가능한지 의심 스럽습니다. – Nebr