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

The Human Context: Exploring Google's Nearby AP...

The Human Context: Exploring Google's Nearby APIs (Video)

A high-level overview of the cross-platform Nearby APIs introduced in 2015. Covers capabilities, practicalities, responsibilities, and opportunities!

Video: https://www.youtube.com/watch?v=fKSqMsCTDiI
Venue: Self Conference 2016

Stuart Kent

May 20, 2016
Tweet

More Decks by Stuart Kent

Other Decks in Programming

Transcript

  1. 2001 "My internet browser heard us saying the word Fry

    and it found a movie about Philip J. Fry for us. It also opened my calendar to Friday and ordered me some french fries."
  2. • detect and communicate with nearby devices • simple pub/sub

    API • iOS & Android The Nearby Messages API
  3. • detect and communicate with nearby devices • simple pub/sub

    API • iOS & Android • unauthenticated* The Nearby Messages API
  4. • detect and communicate with nearby devices • simple pub/sub

    API • iOS & Android • unauthenticated* • default (~100ft) and earshot (~ 5ft) ranges The Nearby Messages API
  5. • detect and communicate with nearby devices • simple pub/sub

    API • iOS & Android • unauthenticated* • default (~100ft) and earshot (~ 5ft) ranges • [BLE beacon support] The Nearby Messages API
  6. Roles Publisher 0 or 1 messages Handheld (dynamic) + Beacon

    (static) Subscriber Multiple messages Handheld
  7. Roles Publisher 0 or 1 messages Handheld (dynamic) + Beacon

    (static) Subscriber Multiple messages Handheld
  8. • Byte array (JSON, protocol buffers) • Recommended: < 3kb

    (Android); "fairly small" (iOS) 
 Messages
  9. • Byte array (JSON, protocol buffers) • Recommended: < 3kb

    (Android); "fairly small" (iOS) • Max: 100kb (Android & iOS)
 Messages
  10. • Byte array (JSON, protocol buffers) • Recommended: < 3kb

    (Android); "fairly small" (iOS) • Max: 100kb (Android & iOS)
 ↳ Send references, not resources Messages
  11. • Tokens communicated using Bluetooth/speaker+mic
 ↳ range control
 ↳ heavy

    battery usage • Message content delivered via Google servers Summary
  12. • Tokens communicated using Bluetooth/speaker+mic
 ↳ range control
 ↳ heavy

    battery usage • Message content delivered via Google servers
 ↳ security/insecurity? Summary
  13. • Tokens communicated using Bluetooth/speaker+mic
 ↳ range control
 ↳ heavy

    battery usage • Message content delivered via Google servers
 ↳ security/insecurity? 
 ↳ connectivity requirement Summary
  14. • Tokens communicated using Bluetooth/speaker+mic
 ↳ range control
 ↳ heavy

    battery usage • Message content delivered via Google servers
 ↳ security/insecurity?
 ↳ connectivity requirement • Apps must share Google Developers Console project Summary
  15. • Tokens communicated using Bluetooth/speaker+mic
 ↳ range control
 ↳ heavy

    battery usage • Message content delivered via Google servers
 ↳ security/insecurity?
 ↳ connectivity requirement • Apps must share Google Developers Console project
 ↳ more security Summary
  16. • Auth with Google account • Publish photo, name, email

    • See nearby users (100ft) • Save users Calling Card
  17. • Auth with Google account • Publish photo, name, email

    • See nearby users (100ft) • Save users Calling Card
  18. • Auth with Google account • Publish photo, name, email

    • See nearby users (100ft) Calling Card
  19. • Auth with Google account • Publish photo, name, email

    • See nearby users (100ft) • Save contact info Calling Card
  20. Apps must handle: • runtime permission (Bluetooth/Audio) • message serialization

    & deserialization • notification kill (Android) Implementation Notes
  21. Apps must handle: • runtime permission (Bluetooth/Audio) • message serialization

    & deserialization • notification kill (Android) • teardown Implementation Notes
  22. <application>
 ... <!-- API key from Google API Console -->


    <meta-data
 android:name="com.google.android.nearby.messages.API_KEY"
 android:value="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" /> 
 ... 
 </application> AndroidManifest.xml
  23. Nearby.Messages.publish(googleApiClient, message, pubOptions) //////////////////////////////////////////////////////////////////// @Override
 public void onConnectionFailed(ConnectionResult result) {


    if (result.hasResolution()) {
 try {
 result.startResolutionForResult(this, NEARBY_CODE);
 } catch (final IntentSender.SendIntentException e) {
 // cancel all Nearby operations
 }
 } else { // cancel all Nearby operations }
 } NearbyActivity.java
  24. Nearby.Messages.publish(googleApiClient, message, pubOptions) //////////////////////////////////////////////////////////////////// @Override
 public void onConnectionFailed(ConnectionResult result) {


    if (result.hasResolution()) {
 try {
 result.startResolutionForResult(this, NEARBY_CODE);
 } catch (final IntentSender.SendIntentException e) {
 // cancel all Nearby operations
 }
 } else { // cancel all Nearby operations }
 } NearbyActivity.java
  25. Nearby.Messages.publish(googleApiClient, message, pubOptions) //////////////////////////////////////////////////////////////////// @Override
 protected void onActivityResult( int requestCode,

    int resultCode, Intent data) {
 
 if (requestCode == NEARBY_CODE) {
 if (resultCode == RESULT_OK) { googleApiClient.connect(); } else { // cancel all Nearby operations }
 } else {
 super.onActivityResult(requestCode, resultCode, data);
 }
 } NearbyActivity.java
  26. Nearby.Messages.publish(googleApiClient, message, pubOptions) //////////////////////////////////////////////////////////////////// @Override
 protected void onActivityResult( int requestCode,

    int resultCode, Intent data) {
 
 if (requestCode == NEARBY_CODE) {
 if (resultCode == RESULT_OK) { googleApiClient.connect(); } else { // cancel all Nearby operations }
 } else {
 super.onActivityResult(requestCode, resultCode, data);
 }
 } NearbyActivity.java
  27. Nearby.Messages.publish(googleApiClient, message, pubOptions) //////////////////////////////////////////////////////////////////// private Message message; ... User user

    = getIntent().getParcelableExtra(USER_EXTRA_KEY); message = new Message(GSON.toJson(user).getBytes()); NearbyActivity.java
  28. Nearby.Messages.publish(googleApiClient, message, pubOptions) //////////////////////////////////////////////////////////////////// // can also be used to

    set role and range private PublishOptions pubOptions = new PublishOptions.Builder() .setCallback(publishCallback) .build(); NearbyActivity.java
  29. Nearby.Messages.publish(googleApiClient, message, pubOptions) //////////////////////////////////////////////////////////////////// // can also be used to

    set role and range private PublishOptions pubOptions = new PublishOptions.Builder() .setCallback(publishCallback) .build(); ... private PublishCallback publishCallback = new PublishCallback() {
 @Override
 public void onExpired() { // cancel all Nearby operations }
 }; NearbyActivity.java
  30. Nearby.Messages.subscribe(googleApiClient, listener, subOptions) //////////////////////////////////////////////////////////////////// private MessageListener listener = new MessageListener()

    {
 @Override
 public void onFound(Message message) {
 // received once; deserialize data and cache it }
 
 @Override
 public void onLost(Message message) {
 // received once; deserialize data and remove from cache
 }
 }; NearbyActivity.java
  31. @Override
 protected void onStop() {
 // cancel all Nearby operations

    // disconnect GoogleApiClient
 super.onStop();
 } NearbyActivity.java
  32. iOS

  33. private var message: GNSMessage? { guard let userData = user?.toNSData()

    else { return nil } return GNSMessage(content: userData) } NearbyViewController.swift
  34. private var message: GNSMessage? { guard let userData = user?.toNSData()

    else { return nil } return GNSMessage(content: userData) } NearbyViewController.swift
  35. private var permissionProxy: GNSPermission? ... override func viewWillAppear(animated: Bool) {

    super.viewWillAppear(animated) permissionProxy = GNSPermission { [weak self] granted in if granted { // show active UI } else { // show inactive UI } } } NearbyViewController.swift
  36. private var permissionProxy: GNSPermission? ... override func viewWillAppear(animated: Bool) {

    super.viewWillAppear(animated) permissionProxy = GNSPermission { [weak self] granted in if granted { // show active UI } else { // show inactive UI } } } NearbyViewController.swift
  37. private var currentPub: GNSPublication? ... if let message = message

    { // shows permissions request dialog // can also pass params to set role and range currentPub = messageManager.publicationWithMessage(message) } NearbyViewController.swift
  38. private var currentSub: GNSSubscription? ... // can also pass params

    to set role and range currentSub = messageManager.subscriptionWithMessageFoundHandler( { [weak self] foundMessage in // received once; deserialize data and cache it }, messageLostHandler: { [weak self] lostMessage in // received once; deserialize data and remove from cache } ) NearbyViewController.swift
  39. override func viewWillDisappear(animated: Bool) { // cancel all Nearby operations

    super.viewWillDisappear(animated) } NearbyViewController.swift
  40. Privacy Anonymity vs Authenticity "Yik Yak is a location-based social

    network that helps people discover their local community, letting them share news, crack jokes, offer support, ask questions, and interact freely."