本文整理匯總了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);
}
示例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;
}
}
示例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);
}
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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();
}
示例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;
}
示例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();
}
}
示例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");
}
}
}