com.google.android.gms.nearby.messages.Messages |
API which allows your app to publish simple messages and subscribe to receive those messages from nearby devices.
The API performs its operations in an unauthenticated manner, so it does not require a Google account. However, it requires that the developer has a project in the Google Developers Console with the following prerequisites:
<manifest ...>
<application ...>
<meta-data
android:name="com.google.android.nearby.messages.API_KEY"
android:value="SPECIFY_APPLICATION_API_KEY_HERE" />
<activity>
...
</activity>
</application>
</manifest>
The Messages API should be accessed from the Nearby
entry point. For example:
@Override
protected void onCreate(Bundle savedInstanceState) {
mGoogleApiClient = new GoogleApiClient.Builder(context)
.addApi(Nearby.MESSAGES_API)
.addConnectionCallbacks(this)
.build();
}
@Override
protected void onStart() {
mGoogleApiClient.connect();
}
@Override
public void onConnected(Bundle connectionHint) {
PendingResult<Status> pendingResult = Nearby.Messages.publish(mGoogleApiClient,
new Message(bytes));
}
All of the Messages APIs should be used from a foreground Activity. Your Activity should
publish(GoogleApiClient, Message)
or subscribe(GoogleApiClient, MessageListener)
either in
onStart()
or in response to a user action in a visible Activity, and
you should always symmetrically unpublish(GoogleApiClient, Message)
or
unsubscribe(GoogleApiClient, MessageListener)
in onStop()
.
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Checks if the user has granted this app permission to publish and subscribe.
| |||||||||||
Publishes a message so that it is visible to nearby devices, using the default options
from
DEFAULT .
| |||||||||||
This method is deprecated.
Use
publish(GoogleApiClient, Message, PublishOptions) .
| |||||||||||
Publishes a message so that it is visible to nearby devices.
| |||||||||||
Registers a status callback, which will be notified when significant events occur that
affect Nearby for your app.
| |||||||||||
Subscribes for published messages from nearby devices.
| |||||||||||
Subscribes for published messages from nearby devices, using the default options in
DEFAULT .
| |||||||||||
This method is deprecated.
Use
subscribe(GoogleApiClient, MessageListener, SubscribeOptions) .
| |||||||||||
This method is deprecated.
Use
subscribe(GoogleApiClient, MessageListener, SubscribeOptions) .
| |||||||||||
Cancels an existing published message.
| |||||||||||
Unregisters a status callback previously registered with
registerStatusCallback(GoogleApiClient, StatusCallback) .
| |||||||||||
Cancels an existing subscription.
|
Checks if the user has granted this app permission to publish and subscribe. In particular, the status returned can be
APP_NOT_OPTED_IN
- If the app asked for permission
and was denied by user.
SUCCESS
- If the app has permission to publish and subscribe.
client | A connected GoogleApiClient for MESSAGES_API |
---|
PendingResult
which can be used to determine if the app has all the
required permissions to publish/subscribe.
Publishes a message so that it is visible to nearby devices, using the default options
from DEFAULT
.
This method is deprecated.
Use publish(GoogleApiClient, Message, PublishOptions)
.
Publishes a message so that it is visible to nearby devices.
The message is only delivered to apps that share the same project id in the Developer Console and have an active subscription. Create project identifiers and turn on the Nearby API in the Google Developers Console.
client | A connected GoogleApiClient for MESSAGES_API |
---|---|
message | A Message to publish for nearby devices to see |
strategy | A Strategy to use to publish the message |
PendingResult
which can be used to determine if the call succeeded.Publishes a message so that it is visible to nearby devices.
The message is only delivered to apps that share the same project id in the Developer Console and have an active subscription. Create project identifiers and turn on the Nearby API in the Google Developers Console.
client | A connected GoogleApiClient for MESSAGES_API |
---|---|
message | A Message to publish for nearby devices to see |
options | A PublishOptions object for this operation |
PendingResult
which can be used to determine if the call succeeded.
Registers a status callback, which will be notified when significant events occur that affect Nearby for your app.
When your app first calls this API, it may be immediately called back with current status.
client | A connected GoogleApiClient for MESSAGES_API . |
---|---|
statusCallback | A callback to notify when events occur. |
PendingResult
which can be used to determine if the call succeeded.Subscribes for published messages from nearby devices.
Only messages published by apps sharing the same project id in the Developer Console will be delivered.
client | A connected GoogleApiClient for MESSAGES_API |
---|---|
listener | A MessageListener implementation to get callbacks of received
messages |
options | A SubscribeOptions object for this operation |
PendingResult
which can be used to determine if the call succeeded.
Subscribes for published messages from nearby devices, using the default options in
DEFAULT
.
This method is deprecated.
Use subscribe(GoogleApiClient, MessageListener, SubscribeOptions)
.
Subscribes for published messages from nearby devices, using
INCLUDE_ALL_MY_TYPES
.
Only messages published by apps sharing the same project id in the Developer Console will be delivered.
client | A connected GoogleApiClient for MESSAGES_API |
---|---|
listener | A MessageListener implementation to get callbacks of received
messages |
strategy | A Strategy to use to subscribe for messages |
PendingResult
which can be used to determine if the call succeeded.
This method is deprecated.
Use subscribe(GoogleApiClient, MessageListener, SubscribeOptions)
.
Subscribes for published messages from nearby devices.
client | A connected GoogleApiClient for MESSAGES_API |
---|---|
listener | A MessageListener implementation to get callbacks of received
messages |
strategy | A Strategy to use to subscribe for messages |
filter | A MessageFilter to specify which messages to receive |
PendingResult
which can be used to determine if the call succeeded.Cancels an existing published message.
If this method is called and the message is not currently published, it will return a
Status
of SUCCESS
.
client | A connected GoogleApiClient for MESSAGES_API |
---|---|
message | A Message that is currently published |
PendingResult
which can be used to determine if the call succeeded.
Unregisters a status callback previously registered with registerStatusCallback(GoogleApiClient, StatusCallback)
.
client | A connected GoogleApiClient for MESSAGES_API . |
---|---|
statusCallback | A callback previously registered with registerStatusCallback(GoogleApiClient, StatusCallback) . |
PendingResult
which can be used to determine if the call succeeded.Cancels an existing subscription.
If this method is called and the listener
is not currently subscribed, it will
return a Status
of SUCCESS
.
client | A connected GoogleApiClient for MESSAGES_API |
---|---|
listener | A MessageListener implementation that is currently subscribed |
PendingResult
which can be used to determine if the call succeeded.