当前位置: 首页>>代码示例>>Java>>正文


Java BluetoothGatt.STATE_CONNECTING属性代码示例

本文整理汇总了Java中android.bluetooth.BluetoothGatt.STATE_CONNECTING属性的典型用法代码示例。如果您正苦于以下问题:Java BluetoothGatt.STATE_CONNECTING属性的具体用法?Java BluetoothGatt.STATE_CONNECTING怎么用?Java BluetoothGatt.STATE_CONNECTING使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在android.bluetooth.BluetoothGatt的用法示例。


在下文中一共展示了BluetoothGatt.STATE_CONNECTING属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: connectWithGatt

private void connectWithGatt() {
    int oldState;
    int newState = BluetoothGatt.STATE_CONNECTING;
    synchronized (lock) {
        oldState = state;
        state = BluetoothGatt.STATE_CONNECTING;
    }

    NeatleLogger.d("Connecting with " + device.getName() + "[" + device.getAddress() + "]");
    BluetoothGatt gatt = device.connectGatt(context, false, callback);

    synchronized (lock) {
        this.gatt = gatt;
        if (gatt == null) {
            state = BluetoothGatt.STATE_DISCONNECTED;
            newState = BluetoothGatt.STATE_DISCONNECTED;
        }
    }

    notifyConnectionStateChange(oldState, newState);
}
 
开发者ID:inovait,项目名称:neatle,代码行数:21,代码来源:Device.java

示例2: onConnectionStateChange

/**
 * 连接状态改变回调
 * 系统自带API
 * @param gatt
 * @param status
 * @param newState
 */
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
    if (BleLog.isPrint) {
        BleLog.i(TAG, "onConnectionStateChange  status: " + status
                + " ,newState: " + newState + "  ,thread: " + Thread.currentThread().getId());
    }
    if (newState == BluetoothGatt.STATE_CONNECTED) {
        connectionState = STATE_CONNECTED;
        // 连接成功
        onConnectSuccess(gatt, status);
    } else if (newState == BluetoothGatt.STATE_DISCONNECTED) {
        connectionState = STATE_DISCONNECTED;
        // 连接失败
        onConnectFailure(new ConnectException(gatt, status));
    } else if (newState == BluetoothGatt.STATE_CONNECTING) {
        connectionState = STATE_CONNECTING;
    }

    // 遍历回调回所有传进了的回调, 给子类处理
    for (BluetoothGattCallback call : callbackList) {
        call.onConnectionStateChange(gatt, status, newState);
    }
}
 
开发者ID:qiu-yongheng,项目名称:Bluetooth_BLE,代码行数:30,代码来源:LiteBluetooth.java

示例3: deviceDiscovered

private void deviceDiscovered() {
    stopDiscovery();

    int state = getState();
    if (state == BluetoothGatt.STATE_CONNECTING) {
        NeatleLogger.i("Device discovered. Continuing with connecting");
        connectWithGatt();
    } else {
        NeatleLogger.e("Device discovered but no longer connecting");
    }
}
 
开发者ID:inovait,项目名称:neatle,代码行数:11,代码来源:Device.java

示例4: run

public void run() {
    stopDiscovery();

    int state = getState();
    if (state == BluetoothGatt.STATE_CONNECTING) {
        NeatleLogger.e("Device no discovered failing connection attempt.");
        connectionFailed(BluetoothGatt.GATT_FAILURE);
    } else {
        NeatleLogger.e("Discover timeout but we are not connecting anymore.");
    }
}
 
开发者ID:inovait,项目名称:neatle,代码行数:11,代码来源:Device.java

示例5: connect

@Override
public void connect() {
    int oldState;
    int newState;
    boolean doConnectGatt = false;
    boolean doDiscovery = false;
    boolean adapterEnabled = adapter != null && adapter.isEnabled();

    synchronized (lock) {
        if (isConnected() || isConnecting()) {
            return;
        }
        if (this.gatt != null) {
            throw new IllegalStateException();
        }

        oldState = state;
        if (!adapterEnabled) {
            //newState = BluetoothAdapter.STATE_OFF;
            NeatleLogger.d("BT off. Won't connect to " + device.getName() + "[" + device.getAddress() + "]");
            connectionFailed(BluetoothGatt.GATT_FAILURE);
            return;
        } else {
            newState = BluetoothGatt.STATE_CONNECTING;
            if (device.getType() == BluetoothDevice.DEVICE_TYPE_UNKNOWN) {
                doDiscovery = true;
            } else {
                doConnectGatt = true;
            }
        }
    }
    //call these methods outside of the lock, to prevent deadlocks
    if (doConnectGatt) {
        connectWithGatt();
        return;
    }
    synchronized (lock) {
        state = newState;
    }

    notifyConnectionStateChange(oldState, newState);

    if (doDiscovery) {
        NeatleLogger.d("Device unknown, let's discover it" + device.getName() + "[" + device.getAddress() + "]");
        discoverDevice();
    }
}
 
开发者ID:inovait,项目名称:neatle,代码行数:47,代码来源:Device.java

示例6: isConnecting

public boolean isConnecting() {
    synchronized (lock) {
        return state == BluetoothGatt.STATE_CONNECTING;
    }
}
 
开发者ID:inovait,项目名称:neatle,代码行数:5,代码来源:Device.java


注:本文中的android.bluetooth.BluetoothGatt.STATE_CONNECTING属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。