Being Notified of Bitplace Events

Your application can be notified when the device enters or leaves any bitplace.

To register your application to be notified of bitplace in and out events, you can use the provided BitplaceEventsBroadcastReceiver class that lets you register a callback which will be invoked with the corresponding BitplaceEvent object:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
BitplaceEventsBroadcastReceiver bitplaceEventsReceiver =
  BitplaceEventsBroadcastReceiver.registerWithHandler(getApplicationContext(),
  new BitplacesBroadcastHandler<BitplaceEvent>() {
      @Override
      public void onReceivedBroadcast(BitplaceEvent event) {
          // do something with the provided BitplaceEvent
          Log.i(TAG, "Received event of type: " + event.getEventType()
          + "for bitplace with ID: " + event.getBitplaceId());
      }
  });

The BitplaceEvent object passed to your callback exposes the following getters to access its data:

Method Return value type Description
getEventType() BitplaceEvent.EventType In this case it can be EventType.BitplaceIN or EventType.BitplaceOUT
getBitplaceId() long ID, on the Bitplaces platform, of the bitplace associated with this event
getBitplaceName() String Name of this bitplace
getForeignBitplaceId() String Your own ID associated to this bitplace
getLatitude() double Latitude corresponding to this bitplace
getLongitude() double Longitude corresponding to this bitplace

To unregister from this event you can just call the unregister() method on the returned instance, passing to it your application context:

1
bitplaceEventsReceiver.unregister(getApplicationContext());

Note about implementing your own BroadcastReceivers

The Bitplaces Android SDK uses local broadcasts to send notifications about bitplace events. There are two ways you can subscribe to a notification:

The first, harder way, by implementing your own Android's BroadcastReceiver and registering it with your application's LocalBroadcastManager for the corresponding event. You can access the name of the BITPLACE_EVENT_NOTIFICATION event through BitplacesService.BroadcastAction.BITPLACE_EVENT_NOTIFICATION.fullName().

The easier way, described above, by using the provided, already implemented, BitplaceEventsBroadcastReceiver broadcast receiver. It will take care of unpacking the broadcasted event data and passing it to your registered listener.