Android外围设备BluetoothGattServerCallback onServiceAdded()没有被调用 [英] Android Peripheral BluetoothGattServerCallback onServiceAdded() not getting called
问题描述
因此,我有一个简单的外围应用程序,可以在运行于Samsung S8手机上的Android Studio中进行编码.我可以很好地设置所有BLE广告和特性,但是在添加服务时.从另一个中央设备(即另一个具有用于发现蓝牙广告的应用程序的手机)连接时,我没有看到预期的结果.
So I have a simple Peripheral application that I am coding in Android Studio running on my Samsung S8 mobile phone. I can setup all my BLE Advertisements and Characteristics just fine but when I add my services. I am not seeing expected results when connected from a another Central device (ie. another mobile phone that has an app to discover bluetooth advertisements).
Android Studio的LogCat输出:
LogCat output from Android Studio:
根据日志,我只能看到2个默认服务,它们是Generic Attribute(1800)和Generic Access(1801),它们是任何Gatt服务器的默认服务.我觉得我缺少"onServiceAdded()"回调,该回调应该告诉服务是否确实已添加且可发现.
As per the Log, I can only see 2 default services that are Generic Attribute(1800) and Generic Access (1801) which are the default services for any Gatt server. I feel that I am missing the "onServiceAdded()" callback that is supposed to tell whether the service was indeed added and discoverable.
我的代码没有错误,并且addService()调用成功.我的问题是为什么我不能从onServiceAdded()返回响应?而其他诸如OverConnectionStateChange()之类的Override函数似乎可以正常工作.这似乎是非常基础的,我看了无数示例,但似乎无法使这最后一点起作用.任何有解决方案或好的参考文献的人,将不胜感激.
My code has no errors and the addService() call is successful. My question is why am I not able to get a response back from onServiceAdded()? While other Override functions like onConnectionStateChange() seem to work fine. This seems to be very basic and I looked at tons of examples but cant seem to get this last bit to work. Anyone with a solution or some good references to look at would be greatly appreciated.
推荐答案
我遇到了同样的问题(诺基亚6.1),尽管我添加了2个服务并且随机获取,但onServiceAdded仅被调用了一次
I hade the same issue (Nokia 6.1) where onServiceAdded was called only once although I was adding 2 services and I was getting randomly
onCharacteristicReadRequest() no char for handle nnn
当尝试从另一台设备连接时.
when trying to connect from another device.