本文整理汇总了Java中android.bluetooth.BluetoothGatt.close方法的典型用法代码示例。如果您正苦于以下问题:Java BluetoothGatt.close方法的具体用法?Java BluetoothGatt.close怎么用?Java BluetoothGatt.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.bluetooth.BluetoothGatt
的用法示例。
在下文中一共展示了BluetoothGatt.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onServicesDiscovered
import android.bluetooth.BluetoothGatt; //导入方法依赖的package包/类
@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
if(status == BluetoothGatt.GATT_SUCCESS){
for(BluetoothGattService service : gatt.getServices()){
Log.d(mTAG, "service: " + service.getUuid().toString());
}
//Log.d(mTAG, "mGattMiFloraService: " + UUID_MI_FLORA_SERVICE_ID.toString());
mGattMiFloraService = gatt.getService(UUID_MI_FLORA_SERVICE_ID);
if(mGattMiFloraService != null){
boolean rs = gatt.readCharacteristic(mGattMiFloraService.getCharacteristic(UUID_MI_FLORA_FIRMWARE));
if(!rs){
Log.i(mTAG, "Can't read mGattMiFloraFwCharacteristic");
}
}
}
else{
gatt.close();
mIsConnecting = false;
}
}
示例2: onCharacteristicChanged
import android.bluetooth.BluetoothGatt; //导入方法依赖的package包/类
@Override
public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
Log.d(mTAG, "onCharacteristicChanged");
byte[] mValue = characteristic.getValue();
if(characteristic.getUuid().equals(UUID_nRF51822_GET_TEMP)){
mAirTemperature = (mValue[0] << 8 | mValue[1])/10;
gatt.setCharacteristicNotification(characteristic, false);
List<BluetoothGattCharacteristic> lstChars = mGattnRF51822Service.getCharacteristics();
for(BluetoothGattCharacteristic mCharacteristic : lstChars){
List<BluetoothGattDescriptor> descriptors = mCharacteristic.getDescriptors();
BluetoothGattDescriptor mGattnRF51822Descriptor = mCharacteristic.getDescriptor(UUID_nRF51822_DESCRIPTOR_ID);
if(mGattnRF51822Descriptor != null && mCharacteristic.getUuid().equals(UUID_nRF51822_GET_LIGHT)){
gatt.setCharacteristicNotification(mCharacteristic, true);
byte[] mDesValue = {0x01, 0x00};
mGattnRF51822Descriptor.setValue(mDesValue);
gatt.writeDescriptor(mGattnRF51822Descriptor);
}
}
}
else if(characteristic.getUuid().equals(UUID_nRF51822_GET_LIGHT)){
mLight = (mValue[0] << 8 | mValue[1]);
gatt.close();
Log.d(mTAG, "onCharacteristicChanged data=" + getData());
mIsConnecting = false;
}
}
示例3: onServicesDiscovered
import android.bluetooth.BluetoothGatt; //导入方法依赖的package包/类
@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
if(status == BluetoothGatt.GATT_SUCCESS){
mGattnTitagBatteryService = gatt.getService(UUID_TITAG_BATTERY_SERVICE);
mGattnTitagTempHumidityService = gatt.getService(UUID_TITAG_AIR_TEMP_HUMIDITY_SERVICE);
mGattnTitagLightService = gatt.getService(UUID_TITAG_LIGHT_SERVICE);
if(mGattnTitagBatteryService != null){
gatt.readCharacteristic(mGattnTitagBatteryService.getCharacteristic(UUID_TITAG_GET_BATTERY));
}
}
else{
gatt.close();
mIsConnecting = false;
}
}
示例4: onOWStateChangedToDisconnected
import android.bluetooth.BluetoothGatt; //导入方法依赖的package包/类
private void onOWStateChangedToDisconnected(BluetoothGatt gatt) {
updateLog("We got disconnected from our Device: " + gatt.getDevice().getAddress());
mainActivity.deviceConnectedTimer(false);
mOWDevice.isConnected.set(false);
App.INSTANCE.releaseWakeLock();
mScanResults.clear();
if (App.INSTANCE.getSharedPreferences().shouldAutoReconnect()) {
updateLog("Attempting to Reconnect to " + mOWDevice.deviceMacAddress.get());
BluetoothDevice device = mBluetoothAdapter.getRemoteDevice(mOWDevice.deviceMacAddress.get());
connectToDevice(device);
//scanLeDevice(true);
} else {
gatt.close();
}
mainActivity.invalidateOptionsMenu();
}
示例5: onStep
import android.bluetooth.BluetoothGatt; //导入方法依赖的package包/类
/**
* Will handle cleaning up resources and starting the discovery again if the step was not
* successful
*
* @param gatt The {@link BluetoothGatt} to clean up
* @param success boolean indicating whether or not step was successful
*/
private void onStep(BluetoothGatt gatt, boolean success) {
// Close the BluetoothGatt, update GUI and start scanning again if step was not
// successful
if (!success) {
gatt.close();
bluetoothGatt = null;
runOnUiThread(new Runnable() {
@Override
public void run() {
deviceAddressTextView.setText("");
}
});
startDiscovery();
}
}
示例6: onServicesDiscovered
import android.bluetooth.BluetoothGatt; //导入方法依赖的package包/类
@Override
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
Log.d(mTAG, "onServicesDiscovered");
if(status == BluetoothGatt.GATT_SUCCESS){
mGattnRF51822Service = gatt.getService(UUID_nRF51822_SERVICE_ID);
if(mGattnRF51822Service != null){
List<BluetoothGattCharacteristic> lstChars = mGattnRF51822Service.getCharacteristics();
for(BluetoothGattCharacteristic mCharacteristic : lstChars){
List<BluetoothGattDescriptor> descriptors = mCharacteristic.getDescriptors();
BluetoothGattDescriptor mGattnRF51822Descriptor = mCharacteristic.getDescriptor(UUID_nRF51822_DESCRIPTOR_ID);
if(mGattnRF51822Descriptor != null && mCharacteristic.getUuid().equals(UUID_nRF51822_GET_TEMP)){
gatt.setCharacteristicNotification(mCharacteristic, true);
byte[] mValue = {0x01, 0x00};
mGattnRF51822Descriptor.setValue(mValue);
gatt.writeDescriptor(mGattnRF51822Descriptor);
}
}
}
}
else{
gatt.close();
mIsConnecting = false;
}
}
示例7: close
import android.bluetooth.BluetoothGatt; //导入方法依赖的package包/类
/**
* 关闭蓝牙连接,会释放BluetoothGatt持有的所有资源
* @param address
*/
public boolean close(String address) {
if (!isEmpty(address) && gattMap.containsKey(address)){
Logger.w( "close gatt server " + address);
BluetoothGatt mBluetoothGatt = gattMap.get(address);
mBluetoothGatt.close();
gattMap.remove(address);
updateConnectState(address, ConnectState.NORMAL);
return true;
}
return false;
}
示例8: close
import android.bluetooth.BluetoothGatt; //导入方法依赖的package包/类
/**
* close bluetooth, release resource
* @param address
*/
public boolean close(String address) {
if (!isEmpty(address) && gattMap.containsKey(address)){
Logger.w("close gatt server " + address);
BluetoothGatt mBluetoothGatt = gattMap.get(address);
mBluetoothGatt.close();
gattMap.remove(address);
updateConnectStateListener(address, ConnectState.NORMAL);
return true;
}
return false;
}
示例9: onConnectionStateChange
import android.bluetooth.BluetoothGatt; //导入方法依赖的package包/类
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
boolean didConnect = false;
NeatleLogger.d("onConnectionStateChange status: " + status + " newState:" + newState);
if (newState == BluetoothGatt.STATE_CONNECTED && status == BluetoothGatt.GATT_SUCCESS) {
didConnect = gatt.discoverServices();
}
if (!didConnect) {
gatt.close();
connectionFailed(status);
} else {
connectionSuccess();
}
}
示例10: 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;
}
示例11: closeBluetoothGatt
import android.bluetooth.BluetoothGatt; //导入方法依赖的package包/类
/**
* 关闭GATT连接
* @param gatt
*/
public static void closeBluetoothGatt(BluetoothGatt gatt) {
if (gatt != null) {
gatt.disconnect();
refreshDeviceCache(gatt);
gatt.close();
}
}
示例12: close
import android.bluetooth.BluetoothGatt; //导入方法依赖的package包/类
/**
* After using a given BLE device, the app must call this method to ensure resources are released properly.
*/
public void close() {
Set<String> macs = mBluetoothGatts.keySet();
for (String deviceMac : macs) {
BluetoothGatt bluetoothGatt = mBluetoothGatts.get(deviceMac);
if (bluetoothGatt != null) {
bluetoothGatt.close();
mBluetoothGatts.remove(deviceMac);
}
}
}
示例13: onDisconnected
import android.bluetooth.BluetoothGatt; //导入方法依赖的package包/类
private void onDisconnected(BluetoothGatt gatt) {
gatt.close();
BlePair pair = bluetoothGatt.get(gatt.getDevice().getAddress());
if (pair != null) {
bluetoothGatt.remove(gatt.getDevice().getAddress());
sendBroadcast(
new Intent(DEVICE_DISCONNECTED)
.putExtra(DEVICE_ADDRESS, gatt.getDevice().getAddress())
);
}
if (bluetoothGatt.size() == 0) {
stopSelf();
}
}
示例14: 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");
}
}
}
示例15: onConnectionStateChange
import android.bluetooth.BluetoothGatt; //导入方法依赖的package包/类
@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
if (newState == BluetoothProfile.STATE_CONNECTED) {
//gatt.discoverServices();
gatt.requestMtu(69);
if (mProvServerDev != null) {
if (mProvServerDev.getGattClient() != null) {
if (mProvServerDev.getGattClient().equals(gatt)) {
//mProvServerDev.setConnectionState(PeerDevice.STATE_CONNECTED);
}
}
}
if (mProxyDev != null) {
if (mProxyDev.getGattClient() != null) {
if (mProxyDev.getGattClient().equals(gatt)) {
//mProxyDev.setConnectionState(PeerDevice.STATE_CONNECTED);
}
}
}
if (D) {
Log.i(TAG, "Connected to GATT server.");
}
} else if (newState == BluetoothProfile.STATE_DISCONNECTED) {
boolean retry = false;
if (mProvServerDev != null) {
if (mProvServerDev.getGattClient() != null) {
if (mProvServerDev.getGattClient().equals(gatt)) {
if (mProvServerDev.getConnectionState() == PeerDevice.STATE_CONNECTING) {
Log.i(TAG, "connect failed, try again, status="+status);
gatt.connect();
retry = true;
} else {
mProvServerDev.setConnectionState(PeerDevice.STATE_DISCONNECTED);
gatt.close();
mProvServerDev = null;
}
}
}
}
if (mProxyDev != null) {
if (mProxyDev.getGattClient() != null) {
if (mProxyDev.getGattClient().equals(gatt)) {
if (mProxyDev.getConnectionState() == PeerDevice.STATE_CONNECTING) {
Log.i(TAG, "connect failed, try again, status="+status);
gatt.connect();
retry = true;
} else {
mProxyDev.setConnectionState(PeerDevice.STATE_DISCONNECTED);
gatt.close();
mProxyDev = null;
}
}
}
}
if (retry == false) {
if (D) {
Log.i(TAG, "Disconnected from GATT server.");
}
String strAddr=gatt.getDevice().getAddress();
byte[] addr = stringToAddress(strAddr);
connectionChangedNative(addr, false, status);
}
}
}