For an application I have need for an android device to be both a Ble Gatt peripheral and server to accept both incoming and send outgoing messages; however, it seems I cannot find much information pertaining to setting up and maintaining the server other than looking at projects of others in github. Can anyone show me the correct solution or guide me to more information regarding setting up BluetoothGattServer.
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
I would like to quickly mention, that most of the Android devices in use don't support the BluetoothGattServer. However newer models have that capability more and more.
First of all you probably want to advertise your service, so that other devices know about the server. For that we need to create the AdvertiseSettings, the AdvertiseData and the AdvertiseData for ScanResponses.
After that you need to create a callback for the advertising status:
Now you can start advertising your service:
For the BluetoothGattServer we need first to create a BluetoothGattServerCallback:
You don't need to implement all of those methods, only those you are interested in. For example you could implement the onCharacteristicReadRequest(...) method to return data to a device reading the characteristic on your BluetoothGattServer.
After that you can open a GattServer, create your service and add the service to the server:
Now you have setup your BluetoothGattServer with a read characteristic, from which other devices can read. I hope this short summary helps you, otherwise I will try to help you clarify the unclear things.