I am writing a sharing app using Google Nearby. I am using MESSAGES_API to publish a message and subscribe to others. The problem is that once a device publishes a message, it will no longer receive messages. I have several devices I am testing - any of which can initially publish a message and other devices receive it. However, if any of the other devices decide they want to publish, the original publisher fails to receive.
How can I continue to receive messages once I publish?
I init my google client here:
mGoogleApiClient = new GoogleApiClient.Builder(mContext)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.addApi(Nearby.MESSAGES_API)
.enableAutoManage(this, this)
.build();
after the google client is connected, I "subscribe' to it
Nearby.Messages.registerStatusCallback(mGoogleApiClient, new StatusCallback() {
@Override
public void onPermissionChanged(boolean b) {
super.onPermissionChanged(b);
Log.d(TAG, "Permission = " + b);
}
});
And, I have a listener to react to messages
Nearby.Messages.subscribe(mGoogleApiClient, mMessageListener).setResultCallback(new ErrorCheckingCallback("subscribe"));
MessageListener mMessageListener = new MessageListener() {
@Override
public void onFound(Message message) {
String messageAsString = new String(message.getContent());
Toast.makeText(mContext, "Incoming Image...", Toast.LENGTH_SHORT).show();
Log.d(TAG, "Found message: " + messageAsString);
}
@Override
public void onLost(Message message) {
String messageAsString = new String(message.getContent());
Log.d(TAG, "Lost sight of message: " + messageAsString);
}
};