3

How via android I can access to GATT error codes

Instead of doing this:

override fun onConnectionStateChange(gatt: BluetoothGatt?, status: Int, newState: Int) {
            super.onConnectionStateChange(gatt, status, newState)

             if (status == 133) {
               //Do something
            }
        }

I wish to do simething like this:

override fun onConnectionStateChange(gatt: BluetoothGatt?, status: Int, newState: Int) {
            super.onConnectionStateChange(gatt, status, newState)

             if (status == <WhatGoesHere?>.GATT_ERROR) {
               //Do something
            }
        }
Dim
  • 4,527
  • 15
  • 80
  • 139
  • 2
    Unfortunately there is no way. Recently I've taken a look at this library https://github.com/weliem/blessed-android I've found this code pretty interesting since it contains a lot of good ideas for handling all the Android messy things about bluetooth. Good luck – cristallo May 25 '21 at 09:43

1 Answers1

2

A few of them you can get from android.bluetooth.BluetoothGatt, but not a lot of the interesting ones you want. I recommend making a GattStatus class that just has integer constants with the codes you linked to, or at least the ones you care about. It's what we ended up doing for our project and it's easily re-usable in the future

Douglas Jones
  • 2,522
  • 1
  • 23
  • 27