本文整理汇总了Java中android.bluetooth.BluetoothProfile.STATE_DISCONNECTED属性的典型用法代码示例。如果您正苦于以下问题:Java BluetoothProfile.STATE_DISCONNECTED属性的具体用法?Java BluetoothProfile.STATE_DISCONNECTED怎么用?Java BluetoothProfile.STATE_DISCONNECTED使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.bluetooth.BluetoothProfile
的用法示例。
在下文中一共展示了BluetoothProfile.STATE_DISCONNECTED属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onConnectionStateChange
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
Log.e(TAG, "onConnectionStateChanged");
String intentAction;
if (newState == BluetoothProfile.STATE_CONNECTED) { // STATE : connected
intentAction = ACTION_GATT_CONNECTED;
mConnectionState = STATE_CONNECTED;
broadcastUpdate(intentAction); // broadcast Gatt connection state : connected
Log.e(TAG, "Connected to GATT server.");
Log.e(TAG, "Attempting to start service discovery:" + mBluetoothGatt.discoverServices());
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) { // STATE : disconnected
intentAction = ACTION_GATT_DISCONNECTED;
mConnectionState = STATE_DISCONNECTED;
broadcastUpdate(intentAction); // broadcast Gatt connection state : disconnected
Log.e(TAG, "Disconnected from GATT server.");
}
}
示例2: connect
/**
* Connects to the GATT server hosted on the Bluetooth LE device.
*
* @param address The device address of the destination device.
* @return Return true if the connection is initiated successfully. The connection result is reported asynchronously through the
* {@code BluetoothGattCallback#onConnectionStateChange(android.bluetooth.BluetoothGatt, int, int)} callback.
*/
public void connect(final String address, IBleDeviceListener iBleDeviceListener) {
UdooBluException udooBluException = checkBluetooth(getApplicationContext());
if (udooBluException != null) {
if (iBleDeviceListener != null)
iBleDeviceListener.onError(udooBluException);
} else {
final BluetoothDevice device = mBtAdapter.getRemoteDevice(address);
int connectionState = mBluetoothManager.getConnectionState(device, BluetoothProfile.GATT);
BluetoothGatt bluetoothGatt = checkAndGetGattItem(address);
if (connectionState == BluetoothProfile.STATE_DISCONNECTED) {
// Previously connected device. Try to reconnect.
if (bluetoothGatt != null) {
Log.d(TAG, "Re-use GATT connection");
if (bluetoothGatt.connect()) {
} else {
Log.w(TAG, "GATT re-connect failed.");
}
} else if (device == null) {
Log.w(TAG, "Device not found. Unable to connect.");
} else {
Log.d(TAG, "Create a new GATT connection.");
bluetoothGatt = device.connectGatt(this, false, bluetoothGattCallbackBuilder());
mBluetoothGatts.put(address, bluetoothGatt);
}
} else {
Log.w(TAG, "Attempt to connect in state: " + connectionState);
bond(address);
bluetoothGatt = device.connectGatt(this, false, bluetoothGattCallbackBuilder());
mBluetoothGatts.put(address, bluetoothGatt);
}
}
}
示例3: onConnectionStateChange
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
super.onConnectionStateChange(gatt, status, newState);
if (newState == BluetoothProfile.STATE_CONNECTED) {
connected = true;
gatt.discoverServices();
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
connected = false;
btGatt.close();
btGatt = null;
charSerial = null;
messenger.obtainMessage(MessageConstants.STATUS, StatusCode.Disconnected).sendToTarget();
} else {
messenger.obtainMessage(MessageConstants.ERROR, ErrorCode.Connect).sendToTarget();
taskConnectTimeout.cancel();
}
}
示例4: onConnectionStateChange
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
String intentAction;
if (newState == BluetoothProfile.STATE_CONNECTED) {
intentAction = ACTION_GATT_CONNECTED;
mConnectionState = STATE_CONNECTED;
broadcastUpdate(intentAction);
Log.i(TAG, "Connected to GATT server.");
// Attempts to discover services after successful connection.
Log.i(TAG, "Attempting to start service discovery:" +
mBluetoothGatt.discoverServices());
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
intentAction = ACTION_GATT_DISCONNECTED;
mConnectionState = STATE_DISCONNECTED;
Log.i(TAG, "Disconnected from GATT server.");
broadcastUpdate(intentAction);
}
}
示例5: onConnectionStateChange
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
if (newState == BluetoothProfile.STATE_CONNECTED) {
if(mOnConnectListener!=null)
mOnConnectListener.onConnect(gatt);
Log.i(TAG, "Connected to GATT server.");
// Attempts to discover services after successful connection.
Log.i(TAG, "Attempting to start service discovery:" +
mBluetoothGatt.discoverServices());
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
if(mOnDisconnectListener!=null)
mOnDisconnectListener.onDisconnect(gatt);
Log.i(TAG, "Disconnected from GATT server.");
}
if(mOnConnectStatusChangedListener!=null)
mOnConnectStatusChangedListener.onConnectStatusChanged(gatt,status,newState);
Log.i(TAG, "Changed");
}
示例6: onReceive
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(A2dpSinkHelper.ACTION_CONNECTION_STATE_CHANGED)) {
int oldState = A2dpSinkHelper.getPreviousProfileState(intent);
int newState = A2dpSinkHelper.getCurrentProfileState(intent);
BluetoothDevice device = A2dpSinkHelper.getDevice(intent);
Log.d(TAG, "Bluetooth A2DP sink changing connection state from " + oldState +
" to " + newState + " device " + device);
if (device != null) {
String deviceName = Objects.toString(device.getName(), "a device");
if (newState == BluetoothProfile.STATE_CONNECTED) {
speak("Connected to " + deviceName);
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
speak("Disconnected from " + deviceName);
}
}
}
}
示例7: onConnectionStateChange
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status,
int newState) {
if (newState == BluetoothProfile.STATE_CONNECTED) {
resetConnectionTimeoutChecker();
isSnachConnected = true;
BLEManager.this.gatt = gatt; // TODO check if right device is discovered (instead of another BLE device with a different GATT..)
Log.i("BLE", "Connected to GATT server.");
Log.i("BLE", "Attempting to start service discovery:" + startServiceDiscovery(gatt));
sendBroadcastConnectionChanged(isSnachConnected);
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
isSnachConnected = false;
mConnectionListener.ConnectionLost();
Log.i("BLE", "Disconnected from GATT server.");
}
}
示例8: disconnect
/**
* 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);
}
}
}
示例9: onConnectionStateChange
@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;
}
}
示例10: onConnectionStateChange
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
String intentAction;
if (newState == BluetoothProfile.STATE_CONNECTED) {
intentAction = ACTION_GATT_CONNECTED;
mConnectionState = STATE_CONNECTED;
Log.i(TAG, "Connected to GATT server.");
// Attempts to discover services after successful connection.
Log.i(TAG, "Attempting to start service discovery:" +
mBluetoothGatt.discoverServices());
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
intentAction = ACTION_GATT_DISCONNECTED;
mConnectionState = STATE_DISCONNECTED;
Log.i(TAG, "Disconnected from GATT server.");
}
}
示例11: onConnectionStateChange
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
Config.logi("BluetoothGatt connection State Changed: [" + status + "]" + newState);
String intentAction;
if (newState == BluetoothProfile.STATE_CONNECTED) {
intentAction = ACTION_GATT_CONNECTED;
mConnectionState = STATE_CONNECTED;
broadcastUpdate(intentAction, gatt.getDevice().getAddress());
Log.i(TAG, "Connected to GATT server.");
// Attempts to discover services after successful connection.
Log.i(TAG, "Attempting to startScan findService discovery:" +
gatt.discoverServices());
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
intentAction = ACTION_GATT_DISCONNECTED;
mConnectionState = STATE_DISCONNECTED;
gatt.close();//make 133 not fire.
Log.i(TAG, "Disconnected from GATT server.");
broadcastUpdate(intentAction, gatt.getDevice().getAddress());
}
}
示例12: onConnectionStateChange
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
String intentAction;
if (newState == BluetoothProfile.STATE_CONNECTED) {
intentAction = ACTION_GATT_CONNECTED;
broadcastUpdate(intentAction);
Log.i(TAG, "Connected to GATT server.");
// Attempts to discover services after successful connection.
Log.i(TAG, "Attempting to start service discovery:" +
mBluetoothGatt.discoverServices());
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
intentAction = ACTION_GATT_DISCONNECTED;
Log.i(TAG, "Disconnected from GATT server.");
broadcastUpdate(intentAction);
}
}
示例13: onConnectionStateChange
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
Log.d(TAG, "Connection State Change: " + status + " -> " + connectionState(newState));
if (status == BluetoothGatt.GATT_SUCCESS && newState == BluetoothProfile.STATE_CONNECTED) {
/*
* Once successfully connected, we must next discover all the services on the
* device before we can read and write their characteristics.
*/
gatt.discoverServices();
mHandler.sendMessage(Message.obtain(null, MSG_PROGRESS, "Discovering Services..."));
} else if (status == BluetoothGatt.GATT_SUCCESS && newState == BluetoothProfile.STATE_DISCONNECTED) {
/*
* If at any point we disconnect, send a message to clear the weather values
* out of the UI
*/
mHandler.sendEmptyMessage(MSG_CLEAR);
} else if (status != BluetoothGatt.GATT_SUCCESS) {
/*
* If there is a failure at any stage, simply disconnect
*/
gatt.disconnect();
}
}
示例14: onConnectionStateChange
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
String intentAction;
if (newState == BluetoothProfile.STATE_CONNECTED) {
intentAction = ACTION_GATT_CONNECTED;
mConnectionState = STATE_CONNECTED;
broadcastUpdate(intentAction, gatt.getDevice());
Log.i(TAG, "Connected to GATT server.");
// Attempts to discover services after successful connection.
Log.i(TAG, "Attempting to start service discovery:" +
mBluetoothGatt.discoverServices());
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
intentAction = ACTION_GATT_DISCONNECTED;
mConnectionState = STATE_DISCONNECTED;
Log.i(TAG, "Disconnected from GATT server.");
gatt.close();
broadcastUpdate(intentAction, gatt.getDevice());
}
}
示例15: onConnectionStateChange
@Override
public void onConnectionStateChange(BluetoothDevice device, int status, int newState) {
if (mProvClientDev != null) {
if (mProvClientDev.getPeerDevice() != null) {
if (mProvClientDev.getPeerDevice().equals(device)) {
String strAddr = device.getAddress();
byte[] addr = stringToAddress(strAddr);
if (newState == BluetoothProfile.STATE_CONNECTED) {
if (mProvClientDev.getConnectionState() == PeerDevice.STATE_DISCONNECTED) {
mProvClientDev.setPeerDevice(device);
mProvClientDev.setConnectionState(PeerDevice.STATE_CONNECTED);
if (D) {
Log.i(TAG, "Connected to GATT Client.");
}
connectionChangedNative(addr, true, status);
}
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
mProvClientDev.setConnectionState(PeerDevice.STATE_DISCONNECTED);
if (D) {
Log.i(TAG, "Disconnected from GATT Client.");
}
advertiseStop();
connectionChangedNative(addr, false, status);
mGattServer.close();
}
}
}
}
}