android.bluetooth.BluetoothGatt#STATE_DISCONNECTING源码实例Demo

下面列出了android.bluetooth.BluetoothGatt#STATE_DISCONNECTING 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Android-nRF-Toolbox   文件: BleManager.java
/**
 * Disconnects from the device or cancels the pending connection attempt. Does nothing if device was not connected.
 * @return true if device is to be disconnected. False if it was already disconnected.
 */
public boolean disconnect() {
	userDisconnected = true;
	initialConnection = false;

	if (bluetoothGatt != null) {
		connectionState = BluetoothGatt.STATE_DISCONNECTING;
		callbacks.onDeviceDisconnecting(bluetoothGatt.getDevice());
		final boolean wasConnected = connected;
		bluetoothGatt.disconnect();

		if (!wasConnected) {
			// There will be no callback, the connection attempt will be stopped
			connectionState = BluetoothGatt.STATE_DISCONNECTED;
			callbacks.onDeviceDisconnected(bluetoothGatt.getDevice());
		}
		return true;
	}
	return false;
}
 
源代码2 项目: EFRConnect-android   文件: LightActivity.java
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
    super.onConnectionStateChange(gatt, status, newState);
    if (newState == BluetoothGatt.STATE_DISCONNECTED || newState == BluetoothGatt.STATE_DISCONNECTING) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                disconnectWithModal();
            }
        });
    }
}
 
源代码3 项目: Android-BLE-Library   文件: BleManagerHandler.java
private boolean internalDisconnect() {
	userDisconnected = true;
	initialConnection = false;
	ready = false;

	if (bluetoothGatt != null) {
		connectionState = BluetoothGatt.STATE_DISCONNECTING;
		log(Log.VERBOSE, connected ? "Disconnecting..." : "Cancelling connection...");
		final BluetoothDevice device = bluetoothGatt.getDevice();
		if (connected) {
			postCallback(c -> c.onDeviceDisconnecting(device));
			postConnectionStateChange(o -> o.onDeviceDisconnecting(device));
		}
		log(Log.DEBUG, "gatt.disconnect()");
		bluetoothGatt.disconnect();
		final boolean wasConnected = connected;
		if (wasConnected)
			return true;

		// If the device wasn't connected, there will be no callback after calling
		// gatt.disconnect(), the connection attempt will be stopped.
		connectionState = BluetoothGatt.STATE_DISCONNECTED;
		log(Log.INFO, "Disconnected");
		postCallback(c -> c.onDeviceDisconnected(device));
		postConnectionStateChange(o -> o.onDeviceDisconnected(device, ConnectionObserver.REASON_SUCCESS));
	}
	// request may be of type DISCONNECT or CONNECT (timeout).
	// For the latter, it has already been notified with REASON_TIMEOUT.
	if (request != null && request.type == Request.Type.DISCONNECT) {
		if (bluetoothDevice != null)
			request.notifySuccess(bluetoothDevice);
		else
			request.notifyInvalidRequest();
	}
	nextRequest(true);
	return true;
}
 
源代码4 项目: RxAndroidBle   文件: RxBleGattCallback.java
static RxBleConnectionState mapConnectionStateToRxBleConnectionStatus(int newState) {

        switch (newState) {
            case BluetoothGatt.STATE_CONNECTING:
                return RxBleConnectionState.CONNECTING;
            case BluetoothGatt.STATE_CONNECTED:
                return RxBleConnectionState.CONNECTED;
            case BluetoothGatt.STATE_DISCONNECTING:
                return RxBleConnectionState.DISCONNECTING;
            default:
                return RxBleConnectionState.DISCONNECTED;
        }
    }
 
源代码5 项目: Android-nRF-Toolbox   文件: BleProfileService.java
/**
 * Disconnects from the sensor.
 */
public final void disconnect() {
    final int state = bleManager.getConnectionState();
    if (state == BluetoothGatt.STATE_DISCONNECTED || state == BluetoothGatt.STATE_DISCONNECTING) {
        bleManager.close();
        onDeviceDisconnected(bluetoothDevice);
        return;
    }

    bleManager.disconnect().enqueue();
}
 
源代码6 项目: RxAndroidBle   文件: RxBleGattCallback.java
private boolean isDisconnectedOrDisconnecting(int newState) {
    return newState == BluetoothGatt.STATE_DISCONNECTED || newState == BluetoothGatt.STATE_DISCONNECTING;
}
 
源代码7 项目: AsteroidOSSync   文件: P_NativeDeviceWrapper.java
boolean isNativelyDisconnecting()
{
	return getConnectionState() == BluetoothGatt.STATE_DISCONNECTING;
}
 
源代码8 项目: SweetBlue   文件: P_NativeDeviceWrapper.java
boolean isNativelyDisconnecting()
{
	return getConnectionState() == BluetoothGatt.STATE_DISCONNECTING;
}