Android Nearby Messages
-
Upload
vishal-nayak -
Category
Technology
-
view
243 -
download
0
Transcript of Android Nearby Messages
OverviewIntroduced in Google Play services 7.8
Nearby provides a proximity API, Nearby Messages, for iOS and Android devices to discover and communicate with each other, as well as with beacons.
Nearby uses a combination of Bluetooth, Wi-Fi, and inaudible sound (using the device’s speaker and microphone) to establish proximity.
The set of nearby devices is determined by the exchange of small tokens over Bluetooth and ultrasonic (inaudible) audio.
Publish a messageTo publish a message, call Nearby.Messages.publish() passing your message byte array, as shown in the following snippet:
// Publish bytes to sendmessage = new Message(yourByteArray);
Nearby.Messages.publish(mGoogleApiClient, message).setResultCallback(new ErrorCheckingCallback("publish()"));
Subscribe to messagesTo subscribe to and retrieve messages, create an instance of MessageListener, then call Nearby.Messages.subscribe(), as shown in the following snippet:// Create an instance of MessageListener
messageListener = new MessageListener() {
@Override
public void onFound(final Message message) {
// Do something with message.getContent()
}
};
// Subscribe to receive messages
Nearby.Messages.subscribe(mGoogleApiClient, messageListener) .setResultCallback(new ErrorCheckingCallback("subscribe()"));
Beacon Communication
Your app can subscribe to Bluetooth Low Energy (BLE) beacons. // Use Strategy.BLE_ONLY because we are only interested in messages that we
// attached to BLE beacons.
Nearby.Messages.subscribe(client, messageListener, Strategy.BLE_ONLY)
.setResultCallback(new ErrorCheckingCallback("subscribe()"));
Use cases/examplesCommunicating with beacons
Trello app - sharing boards with nearby team mates
Edjing Pro - uses Nearby to let DJs publish their tracklist to people around them
Chat apps - chatting with nearby users
References
https://developers.google.com/nearby
https://developers.google.com/nearby/messages/android/get-started?hl=en
http://android-developers.blogspot.jp/2015/07/connect-with-world-around-you-through.html