本文整理汇总了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);
}
示例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);
}
}
示例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");
}
}
示例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.");
}
}
示例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();
}
}
示例6: isConnecting
public boolean isConnecting() {
synchronized (lock) {
return state == BluetoothGatt.STATE_CONNECTING;
}
}