0

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);
    }
};
Martin
  • 4,711
  • 4
  • 29
  • 37
  • Still struggling with Google Nearby. Once a device publishes, it can no longer receive messages via the Message Listener. I tried quite a few things, including forcing subscribe() after every publish(). Although the status says it is subscribed again after having published, it will no longer receive a message.without exiting the Activity and then re-entering. – Martin Apr 07 '17 at 03:24
  • Sorry for belated response... Can you post your publish code? – Brian Duff Jul 06 '17 at 08:20

0 Answers0