MessageListener
Stay organized with collections
Save and categorize content based on your preferences.
A listener for receiving subscribed messages. These callbacks will be delivered when
messages are found or lost.
Public Constructor Summary
Public Method Summary
void |
|
void |
|
void |
|
void |
onLost( Message
message)
Called when a message is no longer detectable nearby.
|
Inherited Method Summary
From class java.lang.Object
Object
|
clone()
|
boolean |
|
void |
finalize()
|
final Class<?>
|
getClass()
|
int |
hashCode()
|
final void |
notify()
|
final void |
notifyAll()
|
String
|
toString()
|
final void |
wait(long arg0, int arg1)
|
final void |
wait(long arg0)
|
final void |
wait()
|
Public Constructors
public MessageListener ()
Public Methods
public void onBleSignalChanged (Message
message, BleSignal
bleSignal)
Called when the Bluetooth Low Energy (BLE) signal associated with a message
changes.
For example, this is called when we see the first BLE advertisement frame associated
with a message; or when we see subsequent frames with different RSSI.
Note: This callback currently only works for BLE beacon
messages.
Note: This callback is not supported by the version of
Messages.subscribe(GoogleApiClient, PendingIntent)
that takes a
PendingIntent
.
public void onDistanceChanged (Message
message, Distance
distance)
Called when Nearby's estimate of the distance to a message changes.
For example, this is called when we first gather enough information to make a
distance estimate; or when the message remains nearby, but gets closer or further
away.
Note: This callback currently only works for BLE beacon
messages.
Note: This callback is not supported by the version of
Messages.subscribe(GoogleApiClient, PendingIntent)
that takes a
PendingIntent
.
Parameters
message |
The message whose distance changed. |
distance |
The new distance estimate. |
public void onFound (Message
message)
Called when messages are found.
This method is called the first time the message is seen nearby. After a message has
been lost (see
onLost(Message)
), it's eligible for
onFound(Message)
again.
Parameters
message |
The found message. |
public void onLost (Message
message)
Called when a message is no longer detectable nearby.
Note: This callback currently works best for BLE beacon messages.
For other messages, it may not be called in a timely fashion, or at all.
This method will not be called repeatedly (unless the message is found again between
lost calls).
Parameters
message |
The lost message. |
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-10-31 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-10-31 UTC."],[[["\u003cp\u003e\u003ccode\u003eMessageListener\u003c/code\u003e is an abstract class used for receiving subscribed messages, providing callbacks when messages are found or lost.\u003c/p\u003e\n"],["\u003cp\u003eIt offers methods to handle changes in Bluetooth Low Energy (BLE) signal strength and estimated distance for nearby messages.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eonFound\u003c/code\u003e is called when a message is first detected, while \u003ccode\u003eonLost\u003c/code\u003e is triggered when a message is no longer detectable.\u003c/p\u003e\n"],["\u003cp\u003eCallbacks related to BLE signal and distance changes are primarily designed for BLE beacon messages and might have limited functionality for other message types.\u003c/p\u003e\n"],["\u003cp\u003eSome callbacks are not supported when subscribing with a \u003ccode\u003ePendingIntent\u003c/code\u003e instead of a \u003ccode\u003eMessageListener\u003c/code\u003e.\u003c/p\u003e\n"]]],[],null,["# MessageListener\n\npublic abstract class **MessageListener** extends [Object](//developer.android.com/reference/java/lang/Object.html) \nA listener for receiving subscribed messages. These callbacks will be delivered when\nmessages are found or lost. \n\n### Public Constructor Summary\n\n|---|------------------------------------------------------------------------------------------------------------------|\n| | [MessageListener](/android/reference/com/google/android/gms/nearby/messages/MessageListener#MessageListener())() |\n\n### Public Method Summary\n\n|------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| void | [onBleSignalChanged](/android/reference/com/google/android/gms/nearby/messages/MessageListener#onBleSignalChanged(com.google.android.gms.nearby.messages.Message,%20com.google.android.gms.nearby.messages.BleSignal))([Message](/android/reference/com/google/android/gms/nearby/messages/Message) message, [BleSignal](/android/reference/com/google/android/gms/nearby/messages/BleSignal) bleSignal) Called when the Bluetooth Low Energy (BLE) signal associated with a message changes. |\n| void | [onDistanceChanged](/android/reference/com/google/android/gms/nearby/messages/MessageListener#onDistanceChanged(com.google.android.gms.nearby.messages.Message,%20com.google.android.gms.nearby.messages.Distance))([Message](/android/reference/com/google/android/gms/nearby/messages/Message) message, [Distance](/android/reference/com/google/android/gms/nearby/messages/Distance) distance) Called when Nearby's estimate of the distance to a message changes. |\n| void | [onFound](/android/reference/com/google/android/gms/nearby/messages/MessageListener#onFound(com.google.android.gms.nearby.messages.Message))([Message](/android/reference/com/google/android/gms/nearby/messages/Message) message) Called when messages are found. |\n| void | [onLost](/android/reference/com/google/android/gms/nearby/messages/MessageListener#onLost(com.google.android.gms.nearby.messages.Message))([Message](/android/reference/com/google/android/gms/nearby/messages/Message) message) Called when a message is no longer detectable nearby. |\n\n### Inherited Method Summary\n\nFrom class java.lang.Object \n\n|----------------------------------------------------------------------------|--------------------------------------------------------------------------------|\n| [Object](//developer.android.com/reference/java/lang/Object.html) | clone() |\n| boolean | equals([Object](//developer.android.com/reference/java/lang/Object.html) arg0) |\n| void | finalize() |\n| final [Class](//developer.android.com/reference/java/lang/Class.html)\\\u003c?\\\u003e | getClass() |\n| int | hashCode() |\n| final void | notify() |\n| final void | notifyAll() |\n| [String](//developer.android.com/reference/java/lang/String.html) | toString() |\n| final void | wait(long arg0, int arg1) |\n| final void | wait(long arg0) |\n| final void | wait() |\n\nPublic Constructors\n-------------------\n\n#### public **MessageListener** ()\n\nPublic Methods\n--------------\n\n#### public void **onBleSignalChanged** ([Message](/android/reference/com/google/android/gms/nearby/messages/Message) message, [BleSignal](/android/reference/com/google/android/gms/nearby/messages/BleSignal) bleSignal)\n\nCalled when the Bluetooth Low Energy (BLE) signal associated with a message\nchanges.\n\nFor example, this is called when we see the first BLE advertisement frame associated\nwith a message; or when we see subsequent frames with different RSSI.\n\n**Note:** This callback currently only works for BLE beacon\nmessages.\n\n**Note:** This callback is not supported by the version of\n[Messages.subscribe(GoogleApiClient, PendingIntent)](/android/reference/com/google/android/gms/nearby/messages/Messages#subscribe(com.google.android.gms.common.api.GoogleApiClient,%20android.app.PendingIntent)) that takes a\n`PendingIntent`. \n\n#### public void **onDistanceChanged** ([Message](/android/reference/com/google/android/gms/nearby/messages/Message) message, [Distance](/android/reference/com/google/android/gms/nearby/messages/Distance) distance)\n\nCalled when Nearby's estimate of the distance to a message changes.\n\nFor example, this is called when we first gather enough information to make a\ndistance estimate; or when the message remains nearby, but gets closer or further\naway.\n\n**Note:** This callback currently only works for BLE beacon\nmessages.\n\n**Note:** This callback is not supported by the version of\n[Messages.subscribe(GoogleApiClient, PendingIntent)](/android/reference/com/google/android/gms/nearby/messages/Messages#subscribe(com.google.android.gms.common.api.GoogleApiClient,%20android.app.PendingIntent)) that takes a\n`PendingIntent`. \n\n##### Parameters\n\n| message | The message whose distance changed. |\n| distance | The new distance estimate. |\n|----------|-------------------------------------|\n\n#### public void **onFound** ([Message](/android/reference/com/google/android/gms/nearby/messages/Message) message)\n\nCalled when messages are found.\n\nThis method is called the first time the message is seen nearby. After a message has\nbeen lost (see [onLost(Message)](/android/reference/com/google/android/gms/nearby/messages/MessageListener#onLost(com.google.android.gms.nearby.messages.Message))), it's eligible for [onFound(Message)](/android/reference/com/google/android/gms/nearby/messages/MessageListener#onFound(com.google.android.gms.nearby.messages.Message)) again. \n\n##### Parameters\n\n| message | The found message. |\n|---------|--------------------|\n\n#### public void **onLost** ([Message](/android/reference/com/google/android/gms/nearby/messages/Message) message)\n\nCalled when a message is no longer detectable nearby.\n\n**Note:** This callback currently works best for BLE beacon messages.\nFor other messages, it may not be called in a timely fashion, or at all.\n\nThis method will not be called repeatedly (unless the message is found again between\nlost calls). \n\n##### Parameters\n\n| message | The lost message. |\n|---------|-------------------|"]]