Nearby API MessageListener doesn't trigger callbacks












1















I am trying to send Beacon Messages from my Eddystone Beacon (micro:bit) to my Android application using Nearby API. I literally copied all their code from documentation but onLost and onFound callbacks are never triggered. The application starts listening and nothing happens then. I know that the beacon is just fine because I can receive messages on Bluetooth Beacon Interactor on my PC.
This is my code:



 mMessageListener = new MessageListener() {
@Override
public void onFound(Message message) {
Log.d("HomepageActivity", "Found message: " + new String(message.getContent()));
mMessageContent.setText(message.getContent().toString());
}

@Override
public void onLost(Message message) {
Log.d("HomepageActivity", "Lost sight of message: " + new String(message.getContent()));
}
};


@OnClick(R.id.mSubscribe)
public void subscribe() {
Log.i("HomepageActivity", "Subscribing.");
SubscribeOptions options = new SubscribeOptions.Builder()
.setStrategy(Strategy.BLE_ONLY)
.build();
Nearby.getMessagesClient(this).subscribe(mMessageListener, options);
}`


This is the whole error message I get in LOGCAT: https://pastebin.com/1UwJ37TV










share|improve this question





























    1















    I am trying to send Beacon Messages from my Eddystone Beacon (micro:bit) to my Android application using Nearby API. I literally copied all their code from documentation but onLost and onFound callbacks are never triggered. The application starts listening and nothing happens then. I know that the beacon is just fine because I can receive messages on Bluetooth Beacon Interactor on my PC.
    This is my code:



     mMessageListener = new MessageListener() {
    @Override
    public void onFound(Message message) {
    Log.d("HomepageActivity", "Found message: " + new String(message.getContent()));
    mMessageContent.setText(message.getContent().toString());
    }

    @Override
    public void onLost(Message message) {
    Log.d("HomepageActivity", "Lost sight of message: " + new String(message.getContent()));
    }
    };


    @OnClick(R.id.mSubscribe)
    public void subscribe() {
    Log.i("HomepageActivity", "Subscribing.");
    SubscribeOptions options = new SubscribeOptions.Builder()
    .setStrategy(Strategy.BLE_ONLY)
    .build();
    Nearby.getMessagesClient(this).subscribe(mMessageListener, options);
    }`


    This is the whole error message I get in LOGCAT: https://pastebin.com/1UwJ37TV










    share|improve this question



























      1












      1








      1








      I am trying to send Beacon Messages from my Eddystone Beacon (micro:bit) to my Android application using Nearby API. I literally copied all their code from documentation but onLost and onFound callbacks are never triggered. The application starts listening and nothing happens then. I know that the beacon is just fine because I can receive messages on Bluetooth Beacon Interactor on my PC.
      This is my code:



       mMessageListener = new MessageListener() {
      @Override
      public void onFound(Message message) {
      Log.d("HomepageActivity", "Found message: " + new String(message.getContent()));
      mMessageContent.setText(message.getContent().toString());
      }

      @Override
      public void onLost(Message message) {
      Log.d("HomepageActivity", "Lost sight of message: " + new String(message.getContent()));
      }
      };


      @OnClick(R.id.mSubscribe)
      public void subscribe() {
      Log.i("HomepageActivity", "Subscribing.");
      SubscribeOptions options = new SubscribeOptions.Builder()
      .setStrategy(Strategy.BLE_ONLY)
      .build();
      Nearby.getMessagesClient(this).subscribe(mMessageListener, options);
      }`


      This is the whole error message I get in LOGCAT: https://pastebin.com/1UwJ37TV










      share|improve this question
















      I am trying to send Beacon Messages from my Eddystone Beacon (micro:bit) to my Android application using Nearby API. I literally copied all their code from documentation but onLost and onFound callbacks are never triggered. The application starts listening and nothing happens then. I know that the beacon is just fine because I can receive messages on Bluetooth Beacon Interactor on my PC.
      This is my code:



       mMessageListener = new MessageListener() {
      @Override
      public void onFound(Message message) {
      Log.d("HomepageActivity", "Found message: " + new String(message.getContent()));
      mMessageContent.setText(message.getContent().toString());
      }

      @Override
      public void onLost(Message message) {
      Log.d("HomepageActivity", "Lost sight of message: " + new String(message.getContent()));
      }
      };


      @OnClick(R.id.mSubscribe)
      public void subscribe() {
      Log.i("HomepageActivity", "Subscribing.");
      SubscribeOptions options = new SubscribeOptions.Builder()
      .setStrategy(Strategy.BLE_ONLY)
      .build();
      Nearby.getMessagesClient(this).subscribe(mMessageListener, options);
      }`


      This is the whole error message I get in LOGCAT: https://pastebin.com/1UwJ37TV







      android bluetooth-lowenergy






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 23 '18 at 20:51









      Martin Zeitler

      17.5k34168




      17.5k34168










      asked Nov 23 '18 at 20:24









      doksaradoksara

      85




      85
























          1 Answer
          1






          active

          oldest

          votes


















          0














          the SubscribeOptions.Builder has one method .setCallback() ...



          which permit to assign a SubscribeCallback (which you might be missing).



          that callback only has one method onExpired(). ignoring the expiry most likely caused the crash.






          share|improve this answer


























          • Hmm, I still don't understand. So I have to add methods onFound() and onLost() in SubscribeCallback or what? Give me more details please.

            – doksara
            Nov 24 '18 at 19:19











          • @doksara you need both, the listener and the callback. subscribe() may never be called ...because the logcat does not read Subscribing anywhere. this means the click event already fails. I'd replace @OnClick(R.id.mSubscribe) with something that actually binds the click event. the stack-trace also hints for the onExpired() callback being ignored.

            – Martin Zeitler
            Nov 24 '18 at 21:36













          • Actually, the event suceeds..there is a message in LogCat: 2018-11-24 22:42:26.046 6205-6205/hr.foi.air.microsensor I/HomepageActivity: Subscribing. But after that, simply nothing happens. I tried moving them under same function but it ain't helping.

            – doksara
            Nov 24 '18 at 21:45











          • @doksara it doesn't ...when I search the page for Subscribing it reads 0/0. this means that Log.i("HomepageActivity", "Subscribing."); is never being called. and if there are indeed attempts to subscribe, the connection might not be in the proper state to do so - or it may subscribe somewhere else in code and then subscribe twice. search GitHub for Nordic Semiconductor, for some proven to be working BLE examples.

            – Martin Zeitler
            Nov 24 '18 at 21:52













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53452578%2fnearby-api-messagelistener-doesnt-trigger-callbacks%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          the SubscribeOptions.Builder has one method .setCallback() ...



          which permit to assign a SubscribeCallback (which you might be missing).



          that callback only has one method onExpired(). ignoring the expiry most likely caused the crash.






          share|improve this answer


























          • Hmm, I still don't understand. So I have to add methods onFound() and onLost() in SubscribeCallback or what? Give me more details please.

            – doksara
            Nov 24 '18 at 19:19











          • @doksara you need both, the listener and the callback. subscribe() may never be called ...because the logcat does not read Subscribing anywhere. this means the click event already fails. I'd replace @OnClick(R.id.mSubscribe) with something that actually binds the click event. the stack-trace also hints for the onExpired() callback being ignored.

            – Martin Zeitler
            Nov 24 '18 at 21:36













          • Actually, the event suceeds..there is a message in LogCat: 2018-11-24 22:42:26.046 6205-6205/hr.foi.air.microsensor I/HomepageActivity: Subscribing. But after that, simply nothing happens. I tried moving them under same function but it ain't helping.

            – doksara
            Nov 24 '18 at 21:45











          • @doksara it doesn't ...when I search the page for Subscribing it reads 0/0. this means that Log.i("HomepageActivity", "Subscribing."); is never being called. and if there are indeed attempts to subscribe, the connection might not be in the proper state to do so - or it may subscribe somewhere else in code and then subscribe twice. search GitHub for Nordic Semiconductor, for some proven to be working BLE examples.

            – Martin Zeitler
            Nov 24 '18 at 21:52


















          0














          the SubscribeOptions.Builder has one method .setCallback() ...



          which permit to assign a SubscribeCallback (which you might be missing).



          that callback only has one method onExpired(). ignoring the expiry most likely caused the crash.






          share|improve this answer


























          • Hmm, I still don't understand. So I have to add methods onFound() and onLost() in SubscribeCallback or what? Give me more details please.

            – doksara
            Nov 24 '18 at 19:19











          • @doksara you need both, the listener and the callback. subscribe() may never be called ...because the logcat does not read Subscribing anywhere. this means the click event already fails. I'd replace @OnClick(R.id.mSubscribe) with something that actually binds the click event. the stack-trace also hints for the onExpired() callback being ignored.

            – Martin Zeitler
            Nov 24 '18 at 21:36













          • Actually, the event suceeds..there is a message in LogCat: 2018-11-24 22:42:26.046 6205-6205/hr.foi.air.microsensor I/HomepageActivity: Subscribing. But after that, simply nothing happens. I tried moving them under same function but it ain't helping.

            – doksara
            Nov 24 '18 at 21:45











          • @doksara it doesn't ...when I search the page for Subscribing it reads 0/0. this means that Log.i("HomepageActivity", "Subscribing."); is never being called. and if there are indeed attempts to subscribe, the connection might not be in the proper state to do so - or it may subscribe somewhere else in code and then subscribe twice. search GitHub for Nordic Semiconductor, for some proven to be working BLE examples.

            – Martin Zeitler
            Nov 24 '18 at 21:52
















          0












          0








          0







          the SubscribeOptions.Builder has one method .setCallback() ...



          which permit to assign a SubscribeCallback (which you might be missing).



          that callback only has one method onExpired(). ignoring the expiry most likely caused the crash.






          share|improve this answer















          the SubscribeOptions.Builder has one method .setCallback() ...



          which permit to assign a SubscribeCallback (which you might be missing).



          that callback only has one method onExpired(). ignoring the expiry most likely caused the crash.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 23 '18 at 21:05

























          answered Nov 23 '18 at 20:54









          Martin ZeitlerMartin Zeitler

          17.5k34168




          17.5k34168













          • Hmm, I still don't understand. So I have to add methods onFound() and onLost() in SubscribeCallback or what? Give me more details please.

            – doksara
            Nov 24 '18 at 19:19











          • @doksara you need both, the listener and the callback. subscribe() may never be called ...because the logcat does not read Subscribing anywhere. this means the click event already fails. I'd replace @OnClick(R.id.mSubscribe) with something that actually binds the click event. the stack-trace also hints for the onExpired() callback being ignored.

            – Martin Zeitler
            Nov 24 '18 at 21:36













          • Actually, the event suceeds..there is a message in LogCat: 2018-11-24 22:42:26.046 6205-6205/hr.foi.air.microsensor I/HomepageActivity: Subscribing. But after that, simply nothing happens. I tried moving them under same function but it ain't helping.

            – doksara
            Nov 24 '18 at 21:45











          • @doksara it doesn't ...when I search the page for Subscribing it reads 0/0. this means that Log.i("HomepageActivity", "Subscribing."); is never being called. and if there are indeed attempts to subscribe, the connection might not be in the proper state to do so - or it may subscribe somewhere else in code and then subscribe twice. search GitHub for Nordic Semiconductor, for some proven to be working BLE examples.

            – Martin Zeitler
            Nov 24 '18 at 21:52





















          • Hmm, I still don't understand. So I have to add methods onFound() and onLost() in SubscribeCallback or what? Give me more details please.

            – doksara
            Nov 24 '18 at 19:19











          • @doksara you need both, the listener and the callback. subscribe() may never be called ...because the logcat does not read Subscribing anywhere. this means the click event already fails. I'd replace @OnClick(R.id.mSubscribe) with something that actually binds the click event. the stack-trace also hints for the onExpired() callback being ignored.

            – Martin Zeitler
            Nov 24 '18 at 21:36













          • Actually, the event suceeds..there is a message in LogCat: 2018-11-24 22:42:26.046 6205-6205/hr.foi.air.microsensor I/HomepageActivity: Subscribing. But after that, simply nothing happens. I tried moving them under same function but it ain't helping.

            – doksara
            Nov 24 '18 at 21:45











          • @doksara it doesn't ...when I search the page for Subscribing it reads 0/0. this means that Log.i("HomepageActivity", "Subscribing."); is never being called. and if there are indeed attempts to subscribe, the connection might not be in the proper state to do so - or it may subscribe somewhere else in code and then subscribe twice. search GitHub for Nordic Semiconductor, for some proven to be working BLE examples.

            – Martin Zeitler
            Nov 24 '18 at 21:52



















          Hmm, I still don't understand. So I have to add methods onFound() and onLost() in SubscribeCallback or what? Give me more details please.

          – doksara
          Nov 24 '18 at 19:19





          Hmm, I still don't understand. So I have to add methods onFound() and onLost() in SubscribeCallback or what? Give me more details please.

          – doksara
          Nov 24 '18 at 19:19













          @doksara you need both, the listener and the callback. subscribe() may never be called ...because the logcat does not read Subscribing anywhere. this means the click event already fails. I'd replace @OnClick(R.id.mSubscribe) with something that actually binds the click event. the stack-trace also hints for the onExpired() callback being ignored.

          – Martin Zeitler
          Nov 24 '18 at 21:36







          @doksara you need both, the listener and the callback. subscribe() may never be called ...because the logcat does not read Subscribing anywhere. this means the click event already fails. I'd replace @OnClick(R.id.mSubscribe) with something that actually binds the click event. the stack-trace also hints for the onExpired() callback being ignored.

          – Martin Zeitler
          Nov 24 '18 at 21:36















          Actually, the event suceeds..there is a message in LogCat: 2018-11-24 22:42:26.046 6205-6205/hr.foi.air.microsensor I/HomepageActivity: Subscribing. But after that, simply nothing happens. I tried moving them under same function but it ain't helping.

          – doksara
          Nov 24 '18 at 21:45





          Actually, the event suceeds..there is a message in LogCat: 2018-11-24 22:42:26.046 6205-6205/hr.foi.air.microsensor I/HomepageActivity: Subscribing. But after that, simply nothing happens. I tried moving them under same function but it ain't helping.

          – doksara
          Nov 24 '18 at 21:45













          @doksara it doesn't ...when I search the page for Subscribing it reads 0/0. this means that Log.i("HomepageActivity", "Subscribing."); is never being called. and if there are indeed attempts to subscribe, the connection might not be in the proper state to do so - or it may subscribe somewhere else in code and then subscribe twice. search GitHub for Nordic Semiconductor, for some proven to be working BLE examples.

          – Martin Zeitler
          Nov 24 '18 at 21:52







          @doksara it doesn't ...when I search the page for Subscribing it reads 0/0. this means that Log.i("HomepageActivity", "Subscribing."); is never being called. and if there are indeed attempts to subscribe, the connection might not be in the proper state to do so - or it may subscribe somewhere else in code and then subscribe twice. search GitHub for Nordic Semiconductor, for some proven to be working BLE examples.

          – Martin Zeitler
          Nov 24 '18 at 21:52






















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53452578%2fnearby-api-messagelistener-doesnt-trigger-callbacks%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Wiesbaden

          Marschland

          Dieringhausen