public void notifyNativeConnectionStateCallback(BluetoothGatt gatt, int status, int newState) { if (nativeCallback != null) { nativeCallback.onConnectionStateChange(gatt, status, newState); } }
@Override public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { RxBleLog.d("onConnectionStateChange newState=%d status=%d", newState, status); nativeCallbackDispatcher.notifyNativeConnectionStateCallback(gatt, status, newState); super.onConnectionStateChange(gatt, status, newState); bluetoothGattProvider.updateBluetoothGatt(gatt); if (isDisconnectedOrDisconnecting(newState)) { disconnectionRouter.onDisconnectedException(new BleDisconnectedException(gatt.getDevice().getAddress(), status)); } else if (status != BluetoothGatt.GATT_SUCCESS) { disconnectionRouter.onGattConnectionStateException( new BleGattException(gatt, status, BleGattOperationType.CONNECTION_STATE) ); } connectionStatePublishRelay.accept(mapConnectionStateToRxBleConnectionStatus(newState)); }
@Override public void run() { if (mConnectionState == STATE_DISCONNECTING) mGattCallback.onConnectionStateChange(mBluetoothGatt, BluetoothGatt.GATT_SUCCESS, BluetoothProfile.STATE_DISCONNECTED); } }, 1500);
@Override public void run() { userCallBack.onConnectionStateChange(bluetoothGatt,BluetoothGatt.GATT_SUCCESS, BluetoothProfile.STATE_DISCONNECTED); } },CALLBACK_DELAY_MS);
@Override public void run() { userCallBack.onConnectionStateChange(bluetoothGatt, BluetoothGatt.GATT_SUCCESS, BluetoothProfile.STATE_CONNECTED); } },CALLBACK_DELAY_MS);
@Override public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { super.onConnectionStateChange(gatt, status, newState); switch (newState){ case BluetoothProfile.STATE_CONNECTED: setState(State.STATE_CONNECTED); gatt.discoverServices(); break; case BluetoothProfile.STATE_DISCONNECTED: setState(State.STATE_DISCONNECTED); break; default:break; } }
@Override public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { super.onConnectionStateChange(gatt, status, newState); switch (newState) { case BluetoothProfile.STATE_CONNECTED: print("连接GATT服务成功,开始Service搜索..."); gatt.discoverServices(); break; case BluetoothProfile.STATE_DISCONNECTED: print("断开GATT Server连接."); break; default: break; } }
@Override public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { super.onConnectionStateChange(gatt, status, newState); print(String.format("status:%d, newState:%d", status, newState)); if (status != BluetoothGatt.GATT_SUCCESS) { closeConnect(); } switch (newState) { case BluetoothProfile.STATE_CONNECTED: print("连接GATT服务成功,开始发现服务..."); gatt.discoverServices(); break; case BluetoothProfile.STATE_DISCONNECTED: print("断开GATT服务,Bye"); closeConnect(); break; default: break; } }
@Override public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { super.onConnectionStateChange(gatt, status, newState); Log.i(TAG,"onConnectionStateChange"); if(newState == BluetoothGatt.STATE_DISCONNECTED) { Log.i(TAG, "Disconnected to GATT Server"); mBlutoothGatt = null; mLeDevice = null; mBluetoothLeCharacteristic = null; Log.e(TAG,"disconnected to device"); updateState(STATE.DEVICE_DISCONNECTED); } if(newState == BluetoothGatt.STATE_CONNECTED){ Log.i(TAG, "Connected to GATT Server"); mBlutoothGatt = gatt; updateState(STATE.DEVICE_CONNECTED); mBlutoothGatt.discoverServices(); } }
private void connectionFailed(int status) { BluetoothGattCallback current; int oldState; int newState; LinkedList<BluetoothGattCallback> queueCopy; BluetoothGatt oldGatt; synchronized (lock) { oldState = state; state = BluetoothGatt.STATE_DISCONNECTED; newState = state; serviceDiscovered = false; current = currentCallback; queueCopy = new LinkedList<>(queue); oldGatt = this.gatt; this.gatt = null; } NeatleLogger.i("Connection attempt failed. Notifying all pending operations"); current.onConnectionStateChange(oldGatt, status, BluetoothGatt.STATE_DISCONNECTED); for (BluetoothGattCallback cb : queueCopy) { cb.onConnectionStateChange(oldGatt, status, BluetoothGatt.STATE_DISCONNECTED); } notifyConnectionStateChange(oldState, newState); }
@Override public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { super.onConnectionStateChange(gatt, status, newState); if (newState == BluetoothProfile.STATE_CONNECTED) { mLogger.debug("onConnectionStateChange: STATE_CONNECTED"); gatt.discoverServices(); mGatt = gatt; mRssiTimer = new Timer(); mRssiTimer.schedule(rssiTask, 1000, 1000); } else if (newState == BluetoothProfile.STATE_DISCONNECTED) { mLogger.debug("onConnectionStateChange: STATE_DISCONNECTED"); // This is necessary to handle a disconnect on the copter side stopScan(); mConnected = false; state = State.IDLE; // it should actually be notifyConnectionLost, but there is // no difference between a deliberate disconnect and a lost connection notifyDisconnected(); } else { mLogger.debug("onConnectionStateChange: else: " + newState); stopScan(); mConnected = false; state = State.IDLE; notifyConnectionLost("BLE connection lost"); } }
@Override public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { super.onConnectionStateChange(gatt, status, newState); sendmsg("onConnectionStateChange"); if (newState == BluetoothGatt.STATE_CONNECTED) gatt.discoverServices(); }
@Override public BluetoothGatt answer(InvocationOnMock invocationOnMock) { BluetoothGatt gatt = Mockito.mock(BluetoothGatt.class); BluetoothGattCallback callback = invocationOnMock.getArgument(2); callback.onConnectionStateChange(gatt, 0, BluetoothGatt.STATE_DISCONNECTED); return gatt; } });
@Override public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { super.onConnectionStateChange(gatt, status, newState); BLEData d = findBLEData(gatt); List<ObservableEmitter<BLEData>> emitters = findObservableEmitter(gatt); if (newState == BluetoothProfile.STATE_CONNECTED) { d.connectedState = true; gatt.discoverServices(); } else if (newState == BluetoothProfile.STATE_DISCONNECTED) { d.connectedState = false; } for (ObservableEmitter<BLEData> s : emitters) { s.onNext(d); } }
@Override public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { super.onConnectionStateChange(gatt, status, newState); if (newState == BluetoothProfile.STATE_CONNECTED) { setConnected(true); Log.d(TAG, "Status BLE Connected"); // Attempts to discover services after successful connection. if (mBluetoothGatt != null) { boolean discoverServices = mBluetoothGatt.discoverServices(); Log.i(TAG, "Attempting to start service discovery:" + discoverServices); } else { Log.d(TAG, "BluetoothGatt is null"); } } else if (newState == BluetoothProfile.STATE_DISCONNECTED) { Log.d(TAG, "Status BLE Disconnected"); setDisconnected(true); setConnected(false); } }
@Override public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { super.onConnectionStateChange(gatt, status, newState); if (newState == BluetoothProfile.STATE_CONNECTED) { gatt.discoverServices(); } else { gatt.close(); if (mBluetoothListener != null) { mBluetoothListener.onDisconnected(); } } }
@Override public void run() { device.connectWithGatt(); deviceCallback.getValue().onConnectionStateChange( Mockito.mock(BluetoothGatt.class), 8000, BluetoothGatt.STATE_DISCONNECTED ); } };
@Override public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { super.onConnectionStateChange(gatt, status, newState); if (newState == BluetoothProfile.STATE_CONNECTED) { gatt.discoverServices(); }else if (newState == BluetoothProfile.STATE_DISCONNECTED) { gatt.close(); if (this.disconnectedListener != null) this.disconnectedListener.onNotify(null); } }
}).when(externalCallback).onConnectionStateChange( Mockito.<BluetoothGatt>any(), Mockito.eq(8000),
/** * 蓝牙设备连接状态被改变 * * @param gatt * @param status * @param newState */ @Override public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) { super.onConnectionStateChange(gatt, status, newState); NotifyMessage notifyMessage = new NotifyMessage(); notifyMessage.setTag(tag); notifyMessage.setCode(CodeUtils.SERVICE_ONCONNEXT_STATE); switch (newState) {//对蓝牙反馈的状态进行判断 case BluetoothProfile.STATE_CONNECTED://已链接 bluetoothGatt = gatt; gatt.discoverServices();//调用发现设备中的服务 notifyMessage.setData(true); break; case BluetoothProfile.STATE_DISCONNECTED://已断开 notifyMessage.setData(false); BluetoothGattManager.removeGatt(tag); tag = null; break; default: break; } EventManager.servicePost(notifyMessage); }