当前位置: 首页>>代码示例>>Java>>正文


Java BluetoothGatt.close方法代码示例

本文整理汇总了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;
    }
}
 
开发者ID:dmtan90,项目名称:Sense-Hub-Android-Things,代码行数:21,代码来源:MiFloraSensorEntity.java

示例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;
    }
}
 
开发者ID:dmtan90,项目名称:Sense-Hub-Android-Things,代码行数:27,代码来源:nRF51822SensorEntity.java

示例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;
    }
}
 
开发者ID:dmtan90,项目名称:Sense-Hub-Android-Things,代码行数:16,代码来源:TitagSensorEntity.java

示例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();
}
 
开发者ID:ponewheel,项目名称:android-ponewheel,代码行数:19,代码来源:BluetoothUtilImpl.java

示例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();
    }
}
 
开发者ID:SPINremote,项目名称:sdc-1-quickstart-android,代码行数:23,代码来源:MainActivity.java

示例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;
    }
}
 
开发者ID:dmtan90,项目名称:Sense-Hub-Android-Things,代码行数:25,代码来源:nRF51822SensorEntity.java

示例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;
}
 
开发者ID:Twelvelines,项目名称:AndroidMuseumBleManager,代码行数:16,代码来源:ConnectRequestQueue.java

示例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;
}
 
开发者ID:Twelvelines,项目名称:AndroidMuseumBleManager,代码行数:16,代码来源:BluetoothConnectManager.java

示例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();
    }
}
 
开发者ID:inovait,项目名称:neatle,代码行数:16,代码来源:Device.java

示例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;
}
 
开发者ID:Samsung,项目名称:microbit,代码行数:13,代码来源:DfuBaseService.java

示例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();
    }
}
 
开发者ID:qiu-yongheng,项目名称:Bluetooth_BLE,代码行数:12,代码来源:BluetoothUtil.java

示例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);
        }
    }
}
 
开发者ID:UDOOboard,项目名称:UDOOBluLib-android,代码行数:14,代码来源:UdooBluService.java

示例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();
  }
}
 
开发者ID:drfonfon,项目名称:ITagAntiLost,代码行数:15,代码来源:BleService.java

示例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");
        }
    }
}
 
开发者ID:Samsung,项目名称:microbit,代码行数:73,代码来源:BLEManager.java

示例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);
}
    	}
    }
 
开发者ID:blxble,项目名称:mesh-core-on-android,代码行数:70,代码来源:JniCallbacks.java


注:本文中的android.bluetooth.BluetoothGatt.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。