Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Add Proximity to Apps with Nearby

Add Proximity to Apps with Nearby

How you can use the Nearby API to make your app aware of the devices around it, and a bit of history of the Nearby project.

Video: https://www.youtube.com/watch?v=e3ufn-tY2Ek

Brian Duff

April 07, 2017
Tweet

More Decks by Brian Duff

Other Decks in Programming

Transcript

  1. Proprietary + Confidential Proprietary + Confidential Proprietary + Confidential Agenda

    History & Background Nearby.Messages Nearby.Notifications Nearby.Connections
  2. Subscribing for messages MessageListener listener = new MessageListener() { void

    onFound(Message m) { byte[] bytes = m.getContent(); } }; Nearby.Messages.subscribe(mClient, listener);
  3. Subscribing for beacons in the background private void backgroundSubscribe() {

    SubscribeOptions options = new SubscribeOptions.Builder() .setStrategy(Strategy.BLE_ONLY) .build(); Nearby.Messages.subscribe(mClient, getPendingIntent(), options); } private PendingIntent getPendingIntent() { return PendingIntent.getBroadcast( this, 0, new Intent(this, BeaconMessageReceiver.class), PendingIntent.FLAG_UPDATE_CURRENT); }
  4. Subscribing for beacons in the background private void backgroundSubscribe() {

    SubscribeOptions options = new SubscribeOptions.Builder() .setStrategy(Strategy.BLE_ONLY) .build(); Nearby.Messages.subscribe(mClient, getPendingIntent(), options); } private PendingIntent getPendingIntent() { return PendingIntent.getBroadcast( this, 0, new Intent(this, BeaconMessageReceiver.class), PendingIntent.FLAG_UPDATE_CURRENT); }
  5. Receiving beacon messages @Override public void onReceive(Context context, Intent intent)

    { Nearby.Messages.handleIntent(intent, new MessageListener() { @Override public void onFound(Message message) { // do something with message.getBytes() } @Override public void onLost(Message message) { // Oh noes! My beacon is out of range. } }); }
  6. Advanced beacon features MessageFilter lets you scan for: • PUBLIC

    namespaced attachments in other namespaces • Raw BLE beacon IDs Special beacon callbacks: • onDistanceChanged • onBleSignalChanged
  7. Example: Scan for iBeacons MessageFilter messageFilter = new MessageFilter.Builder() .includeIBeaconIds(PROXIMITY_UUID,

    major, minor) .build(); SubscribeOptions options = new SubscribeOptions.Builder() .setStrategy(Strategy.BLE_ONLY) .setFilter(messageFilter) .build(); @Override public void onFound(Message message) { IBeaconId ibeacon = IBeaconId.from(message); }
  8. Notifications about nearby things Attach URLs, or app intents We'll

    send users to Play Store if app not installed Notifications can be targeted Notifications are a reward for "good behavior", not a guarantee
  9. Example: App Attachment { "title": "Get the app!", "url": "intent://host/path#Intent;scheme=scheme;package=com.yourapp.ui;end;",

    "targeting":[{ "anyOfAppInstallStates": ["NOT_INSTALLED"], "startTimeOfDay": "9:00", "endTimeOfDay": "17:00" }] }
  10. Help! Let us know what you're building Let us know

    what works & doesn't work Let us know what you'd like to see in the future