當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。