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


Java BluetoothGatt.disconnect方法代码示例

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


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

示例1: disconnect

import android.bluetooth.BluetoothGatt; //导入方法依赖的package包/类
@Override
public void disconnect() {
    NeatleLogger.i("Disconnecting");
    stopDiscovery();
    BluetoothGatt target;
    int oldState;

    synchronized (lock) {
        target = gatt;
        gatt = null;
        this.serviceDiscovered = false;
        oldState = state;
        state = BluetoothGatt.STATE_DISCONNECTED;
    }
    if (target != null) {
        target.disconnect();
    }
    notifyConnectionStateChange(oldState, BluetoothGatt.STATE_DISCONNECTED);
}
 
开发者ID:inovait,项目名称:neatle,代码行数:20,代码来源:Device.java

示例2: onConnectionStateChange

import android.bluetooth.BluetoothGatt; //导入方法依赖的package包/类
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
	String intentAction;
	if (newState == BluetoothProfile.STATE_CONNECTED) {
		Log.i(TAG, "Connected to GATT server.");
		if( gatt.getDevice().getBondState() != BluetoothDevice.BOND_BONDED ) {
			broadcastUpdate(ACTION_NOT_PAIRED);
			gatt.disconnect();
			return;
		}
		Log.i(TAG, "Attempting to start service discovery" );
		mBluetoothGatt.discoverServices();
		connected = true;
		broadcastUpdate(ACTION_GATT_CLIENT_CONNECTED);
	}
	else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
		intentAction = ACTION_GATT_CLIENT_DISCONNECTED;
		Log.i(TAG, "Disconnected from GATT server.");
		broadcastUpdate(intentAction);
		connected = false;
	}
}
 
开发者ID:masterjc,项目名称:bluewatcher,代码行数:23,代码来源:BluetoothClientService.java

示例3: disconnect

import android.bluetooth.BluetoothGatt; //导入方法依赖的package包/类
/**
 * Disconnects an existing connection or cancel a pending connection. The disconnection result is reported asynchronously through the
 * {@code BluetoothGattCallback#onConnectionStateChange(android.bluetooth.BluetoothGatt, int, int)} callback.
 */
public void disconnect(String address) {
    if (mBtAdapter == null) {
        Log.w(TAG, "disconnect: BluetoothAdapter not initialized");
        return;
    }
    final BluetoothDevice device = mBtAdapter.getRemoteDevice(address);
    int connectionState = mBluetoothManager.getConnectionState(device, BluetoothProfile.GATT);
    BluetoothGatt bluetoothGatt = checkAndGetGattItem(address);
    if (bluetoothGatt != null) {
        Log.i(TAG, "disconnect");
        if (connectionState != BluetoothProfile.STATE_DISCONNECTED) {
            bluetoothGatt.disconnect();
        } else {
            Log.w(TAG, "Attempt to disconnect in state: " + connectionState);
        }
    }
}
 
开发者ID:UDOOboard,项目名称:UDOOBluLib-android,代码行数:22,代码来源:UdooBluService.java

示例4: onConnectionStateChange

import android.bluetooth.BluetoothGatt; //导入方法依赖的package包/类
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
    LogUtils.d(TAG, "onConnctionStateChange:" + Thread.currentThread().toString());
    if (BluetoothProfile.STATE_CONNECTED == newState) {
        //连接成功
        LogUtils.i(TAG, "onConnectionStateChange():连接成功,得到gatt,status = " + status);
        mState = State.STATE_CONNECTED;

        //发现服务
        boolean b = gatt.discoverServices();
        LogUtils.d(TAG, "试图查询 gatt 上的 services :" + b);

        //发送消息给 Activity
        sendMsgToClient(MsgClient.MSG_GATT_CONNECTED, null);


    } else if (BluetoothProfile.STATE_DISCONNECTED == newState) {
        //返回连接断开的消息
        sendMsgToClient(MsgClient.MSG_CONNECTED_DISMISS, null);

        //取消周期行读取 rssi 的操作
        cancelAllTasks();

        //清除当前 gatt
        refreshDeviceCache();
        gatt.disconnect();//不使用自带的重连功能
        closeGatt();

        //定时重连操作
        mScheduledThreadPool.schedule(task1, Attributes.RE_CONNECTING_TIME, TimeUnit.MILLISECONDS);

        LogUtils.i(TAG, "onConnectionStateChange():连接断开,status = " + status);
        mState = State.STATE_DISCONNECT;

    } else {
        LogUtils.i(TAG, "其它状态: status = " + status + ", newState = " + newState);
    }
}
 
开发者ID:TommyFen,项目名称:NaiveDemos,代码行数:39,代码来源:BleOperationService.java

示例5: disconnect

import android.bluetooth.BluetoothGatt; //导入方法依赖的package包/类
/**
 * 断开蓝牙连接,不会释放BluetoothGatt持有的所有资源,可以调用mBluetoothGatt.connect()很快重新连接上
 * 如果不及时释放资源,可能出现133错误,http://www.loverobots.cn/android-ble-connection-solution-bluetoothgatt-status-133.html
 * @param address
 */
public void disconnect(String address){
    if (!isEmpty(address) && gattMap.containsKey(address)){
        Logger.w("disconnect gatt server " + address);
        BluetoothGatt mBluetoothGatt = gattMap.get(address);
        mBluetoothGatt.disconnect();
        updateConnectState(address, ConnectState.NORMAL);
    }
}
 
开发者ID:Twelvelines,项目名称:AndroidMuseumBleManager,代码行数:14,代码来源:ConnectRequestQueue.java

示例6: disconnect

import android.bluetooth.BluetoothGatt; //导入方法依赖的package包/类
/**
 * 断开蓝牙连接,不会释放BluetoothGatt持有的所有资源,可以调用mBluetoothGatt.connect()很快重新连接上
 * 如果不及时释放资源,可能出现133错误,http://www.loverobots.cn/android-ble-connection-solution-bluetoothgatt-status-133.html
 * @param address
 */
public void disconnect(String address){
    if (!isEmpty(address) && gattMap.containsKey(address)){
        reconnectParamsBean = new ReconnectParamsBean(address);
        reconnectParamsBean.setNumber(1000);
        Logger.w("disconnect gatt server " + address);
        BluetoothGatt mBluetoothGatt = gattMap.get(address);
        mBluetoothGatt.disconnect();
        updateConnectStateListener(address, ConnectState.NORMAL);
    }
}
 
开发者ID:Twelvelines,项目名称:AndroidMuseumBleManager,代码行数:16,代码来源:BluetoothConnectManager.java

示例7: cancelPairing

import android.bluetooth.BluetoothGatt; //导入方法依赖的package包/类
private void cancelPairing(final BluetoothGatt gatt) {
    logi("----> cancelPairing");
    if (mConnectionState != STATE_DISCONNECTED) {
        // Disconnect from the device
        mConnectionState = STATE_DISCONNECTED;
        logi("Disconnecting from the device...");
        gatt.disconnect();
        sendLogBroadcast(LOG_LEVEL_INFO, "Disconnected");
    }
    // Close the device
    refreshDeviceCache(gatt, false); // This should be set to true when DFU Version is 0.5 or lower
    close(gatt);
}
 
开发者ID:Samsung,项目名称:microbit,代码行数:14,代码来源:DfuBaseService.java

示例8: disconnect

import android.bluetooth.BluetoothGatt; //导入方法依赖的package包/类
/**
 * Disconnects from the device. This is SYNCHRONOUS method and waits until the callback returns new state. Terminates immediately if device is already disconnected. Do not call this method
 * directly, use {@link #terminateConnection(android.bluetooth.BluetoothGatt, int)} instead.
 *
 * @param gatt the GATT device that has to be disconnected
 */
private void disconnect(final BluetoothGatt gatt) {
    if (mConnectionState == STATE_DISCONNECTED)
        return;

    mConnectionState = STATE_DISCONNECTING;
    logi("Disconnecting from the device...");
    gatt.disconnect();

    // We have to wait until device gets disconnected or an error occur
    waitUntilDisconnected();
}
 
开发者ID:Samsung,项目名称:microbit,代码行数:18,代码来源:DfuBaseService.java

示例9: close

import android.bluetooth.BluetoothGatt; //导入方法依赖的package包/类
/**
 * Closes the GATT device and cleans up.
 *
 * @param gatt the GATT device to be closed
 */
private void close(final BluetoothGatt gatt) {
    logi("Cleaning up...");
    sendLogBroadcast(LOG_LEVEL_DEBUG, "gatt.close()");
    gatt.disconnect();
    gatt.close();
    mConnectionState = STATE_CLOSED;
}
 
开发者ID:Samsung,项目名称:microbit,代码行数:13,代码来源:DfuBaseService.java

示例10: closeBluetoothGatt

import android.bluetooth.BluetoothGatt; //导入方法依赖的package包/类
/**
 * 关闭GATT连接
 * @param gatt
 */
public static void closeBluetoothGatt(BluetoothGatt gatt) {
    if (gatt != null) {
        gatt.disconnect();
        refreshDeviceCache(gatt);
        gatt.close();
    }
}
 
开发者ID:qiu-yongheng,项目名称:Bluetooth_BLE,代码行数:12,代码来源:BluetoothUtil.java

示例11: onConnectionStateChange

import android.bluetooth.BluetoothGatt; //导入方法依赖的package包/类
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
    super.onConnectionStateChange(gatt, status, newState);

    if(DEBUG) {
        logi("BluetoothGattCallback.onConnectionStateChange() :: start : status = " + status + " newState = " +
                "" + newState);
    }

    int state = BLE_DISCONNECTED;
    int error = 0;

    boolean gattForceClosed = false;

    switch(status) {
        case BluetoothGatt.GATT_SUCCESS: {
            if(newState == BluetoothProfile.STATE_CONNECTED) {
                state = BLE_CONNECTED;
            } else if(newState == BluetoothProfile.STATE_DISCONNECTED) {
                state = BLE_DISCONNECTED;
                if(gatt != null) {
                    if(DEBUG) {
                        logi("onConnectionStateChange() :: gatt != null : closing gatt");
                    }

                    gatt.disconnect();
                    gatt.close();
                    gattForceClosed = true;
                    if(BLEManager.this.gatt.getDevice().getAddress().equals(gatt.getDevice().getAddress())) {
                        BLEManager.this.gatt = null;
                    }
                }
            }
        }
        break;
        default:
            Log.e(TAG, "Connection error: " + GattError.parseConnectionError(status));
            break;
    }

    if(status != BluetoothGatt.GATT_SUCCESS) {
        state = BLE_DISCONNECTED;
        error = BLE_ERROR_FAIL;
    }

    synchronized(locker) {
        if(inBleOp == OP_CONNECT) {
            if(DEBUG) {
                logi("BluetoothGattCallback.onConnectionStateChange() :: inBleOp == OP_CONNECT");
            }

            if(state != (bleState & BLE_CONNECTED)) {
                bleState = state;
            }
            callbackCompleted = true;
            BLEManager.this.error = error;
            extendedError = status;
            locker.notify();
        } else {
            if(DEBUG) {
                logi("onConnectionStateChange() :: inBleOp != OP_CONNECT");
            }

            bleState = state;
            unexpectedDisconnectionListener.handleConnectionEvent(bleState, gattForceClosed);
        }

        if(DEBUG) {
            logi("BluetoothGattCallback.onConnectionStateChange() :: end");
        }
    }
}
 
开发者ID:Samsung,项目名称:microbit,代码行数:73,代码来源:BLEManager.java


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