1

While looking at all examples all I see is to initialize BluetoothGatt object the way used is

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

Now how do I initialize the gatt object without connecting the device. 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. 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.

Thanks much :)

Pritish
  • 1,284
  • 1
  • 19
  • 42

1 Answers1

1

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.

Emil
  • 16,784
  • 2
  • 41
  • 52
  • Do you mean a singleton class that extends GattClientCallBack ? – Pritish Dec 31 '17 at 18:07
  • No. Just a class whose objects have an instance of a BluetoothGatt object. That way you can pass around objects of this class and upon connecting you can assign the member variable to the BluetoothGatt object. And when you close the BluetoothGatt object you set the member variable to null. – Emil Jan 01 '18 at 11:58