简体   繁体   English

如何在BLE中初始化BluetoothGatt对象?

[英]How to initialize BluetoothGatt object in BLE?

While looking at all examples all I see is to initialize BluetoothGatt object the way used is 在查看所有示例时,我看到的只是初始化BluetoothGatt对象的方式是

mGatt = device.connectGatt(activity, false, gattClientCallback); mGatt = device.connectGatt(活动,假,gattClientCallback);

Now how do I initialize the gatt object without connecting the device. 现在如何在不连接设备的情况下初始化gatt对象。 I have a centralized call back class to handle callbacks for device connection , characteristic discovery and other things. 我有一个集中的回调类来处理设备连接,特征发现和其他事情的回调。 But my problem is if I pass mgatt object to the constructor of that class it will go as empty object. 但是我的问题是,如果我将mgatt对象传递给该类的构造函数,它将作为空对象进入。 I can always use 我可以随时使用

@Override
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
    super.onConnectionStateChange(gatt, status, newState);
    try {
        // Log.d("+++++++++++++connectionstatechange", "" + status);
        mBluetoothGatt = gatt;

but is there a way I can initialize it without calling connect function. 但是有一种方法可以在不调用connect函数的情况下对其进行初始化。

Thanks much :) 非常感谢 :)

No there is no other way than connecting. 除了连接,没有其他方法。

You can have a custom class that you pass around. 您可以传递一个自定义类。 This class can have a member variable containing your BluetoothGatt object. 此类可以具有包含您的BluetoothGatt对象的成员变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM