问题
I am trying to read serial data over Bluetooth LE but can't find any code examples for this type of bluetooth and api19. Does any one have an example?
回答1:
There is no profile defined for serial data communication over Bluetooth Low Energy till now. For this one can use the Bluetooth classic only.
In any case, Android devices can not broadcast for advertising packets. They can only scan the advertising packets. Hence, these devices will be in Central mode only. But can act as either server or client.
For Bluetooth chat related app example one can refer Android SDK as, sdk/samples/android-19/legacy/BluetoothChat
The above example is based on Bluetooth classic based on RFCOMM channel for serial communication.
回答2:
Android 5.0 let mobile to be peripheral. So chat will be possible: https://developer.android.com/about/versions/android-5.0.html
回答3:
Bluetooth Classic got the SPP profile. This is not how Bluetooth Low Energy works. In BLE you have 1 or more Services each with 1 or more Characteristics which are basically just bytes in a predefined format which by default can be max 23 bytes.
To send data from one device to another one must be the Master and the other must be Slave. Android API19 does not support the Slave (Peripheral) role, it seems Google still doesn't understand the importance of Bluetooth Low Energy. It's so much more than just Pulse-readers.
You can send from an Android API19 phone to e.g. an iPhone which can be Slave/Peripheral.
You cannot send from an Android API19 phone to another API19 phone. For this you must use Bluetooth Classic SPP profile.
来源:https://stackoverflow.com/questions/21489386/android-bluetooth-le-chat-example