4

I have inherited an Android App that reads a characteristic then closes the connection. For versions 4 and 5 of Android Gatt caches the services and characteristics and on subsequent connections uses the cache. This is good for my application although I am aware it causes others problems.

Recent testing using Android 6.0.1 on a MOTO Play shows that Gatt is not using a cache and requests the services and characteristics on every connection. My App still works but it takes time and uses power which is bad.

After some googling it is not clear to me whether the Gatt cache is enabled after pairing/bonding or just after a connection. My application does not pair or bond.

CDspace
  • 2,639
  • 18
  • 30
  • 36
BillBob
  • 67
  • 4

2 Answers2

0

It does not have anything to do neither with pairing/bonding nor the connection. Android caches the services and characteristics once you perform it's discovery after the connection.

From my experience I've found some devices who always does the discovery, and others who don't doing GATT caching saving quite a lot of time. It's not usual that the peripheral changes it's services or characteristics, so caching is always a good approach. However and unfortunately, there's no way you can manage that through Android API, it's all up to Android and the BLE stack firmware of the device.

GoRoS
  • 5,183
  • 2
  • 43
  • 66
  • 3
    What if I get the following system error: **bt_btif: bta_gattc_cache_load: can't open GATT cache file /data/misc/bluetooth/gatt_cache_000b570c2af8 for reading, error: No such file or directory** – IgorGanapolsky Apr 04 '17 at 21:21
0

According to the specification the GATT db may not be cached if the device is not bonded (and it has a service changed characteristic). So the new behavior is correct. Just use bonding and it will use the cache.

Emil
  • 16,784
  • 2
  • 41
  • 52