本文整理匯總了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;
}
}