app to app: design and surface local apis

110
Ty Smith - @tylersmithnet Sr. Android Engineer, Evernote App to App: Design and Surface Local APIs Sunday, September 29, 13

Upload: ty-smith

Post on 12-May-2015

2.323 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: App to App: Design and Surface Local APIs

Ty Smith - @tylersmithnetSr. Android Engineer, Evernote

App to App: Design and Surface Local APIs

Sunday, September 29, 13

Page 2: App to App: Design and Surface Local APIs

#EC2013

The S Note Story

Sunday, September 29, 13

Page 3: App to App: Design and Surface Local APIs

#EC2013

The S Note Story

Sunday, September 29, 13

Page 4: App to App: Design and Surface Local APIs

#EC2013

The S Note Story

Sunday, September 29, 13

Page 5: App to App: Design and Surface Local APIs

#EC2013

The S Note Story

Sunday, September 29, 13

Page 6: App to App: Design and Surface Local APIs

#EC2013

The S Note Story

Sunday, September 29, 13

Page 7: App to App: Design and Surface Local APIs

#EC2013

The S Note Story

Sunday, September 29, 13

Page 8: App to App: Design and Surface Local APIs

#EC2013

Web API vs Local API

Sunday, September 29, 13

Page 9: App to App: Design and Surface Local APIs

#EC2013

Web API vs Local API

Web API

•Powerful

•Flexible

•Comfortable

•Complex

•Inconsistent data

•Service limitations

Local API

•Immediate results

•Managed complexity

•Consistent data

•Not as available

•Too Simple

Sunday, September 29, 13

Page 10: App to App: Design and Surface Local APIs

#EC2013

Web API vs Local API

Web API

•Powerful

•Flexible

•Comfortable

•Complex

•Inconsistent data

•Service limitations

Local API

•Immediate results

•Managed complexity

•Consistent data

•Not as available

•Too Simple

Sunday, September 29, 13

Page 11: App to App: Design and Surface Local APIs

#EC2013

Web API vs Local API

Web API

•Powerful

•Flexible

•Comfortable

•Complex

•Inconsistent data

•Service limitations

Local API

•Immediate results

•Managed complexity

•Consistent data

•Not as available

•Too Simple

Sunday, September 29, 13

Page 12: App to App: Design and Surface Local APIs

#EC2013

Web API vs Local API

Web API

•Powerful

•Flexible

•Comfortable

•Complex

•Inconsistent data

•Service limitations

Local API

•Immediate results

•Managed complexity

•Consistent data

•Not as available

•Too Simple

Sunday, September 29, 13

Page 13: App to App: Design and Surface Local APIs

#EC2013

Web API vs Local API

Web API

•Powerful

•Flexible

•Comfortable

•Complex

•Inconsistent data

•Service limitations

Local API

•Immediate results

•Managed complexity

•Consistent data

•Not as available

•Too Simple

Sunday, September 29, 13

Page 14: App to App: Design and Surface Local APIs

#EC2013

Web API vs Local API

Web API

•Powerful

•Flexible

•Comfortable

•Complex

•Inconsistent data

•Service limitations

Local API

•Immediate results

•Managed complexity

•Consistent data

•Not as available

•Too Simple

Sunday, September 29, 13

Page 15: App to App: Design and Surface Local APIs

#EC2013

What next?

Sunday, September 29, 13

Page 16: App to App: Design and Surface Local APIs

#EC2013

What next?

Sunday, September 29, 13

Page 17: App to App: Design and Surface Local APIs

#EC2013

Android Components

Sunday, September 29, 13

Page 18: App to App: Design and Surface Local APIs

#EC2013

Android Components

1. Intents

Sunday, September 29, 13

Page 19: App to App: Design and Surface Local APIs

#EC2013

Android Components

1. Intents

2. Content Provider

Sunday, September 29, 13

Page 20: App to App: Design and Surface Local APIs

#EC2013

Android Components

1. Intents

2. Content Provider

3. Account Manager

Sunday, September 29, 13

Page 21: App to App: Design and Surface Local APIs

#EC2013

Android Components

1. Intents

2. Content Provider

3. Account Manager

4. Sync Adapter

Sunday, September 29, 13

Page 22: App to App: Design and Surface Local APIs

#EC2013

Android Components

1. Intents

2. Content Provider

3. Account Manager

4. Sync Adapter

5. Bound Service

Sunday, September 29, 13

Page 23: App to App: Design and Surface Local APIs

#EC2013

Intents

Sunday, September 29, 13

Page 24: App to App: Design and Surface Local APIs

#EC2013

Intents

•Simple message between two components

Sunday, September 29, 13

Page 25: App to App: Design and Surface Local APIs

#EC2013

Intents

•Simple message between two components

•Bundle - key/value data

Sunday, September 29, 13

Page 26: App to App: Design and Surface Local APIs

#EC2013

Intents

•Simple message between two components

•Bundle - key/value data

•Limited payload size (500k)

Sunday, September 29, 13

Page 27: App to App: Design and Surface Local APIs

#EC2013

Intents

•Simple message between two components

•Bundle - key/value data

•Limited payload size (500k)

•Inefficient for batch operations

Sunday, September 29, 13

Page 28: App to App: Design and Surface Local APIs

#EC2013

Intents

•Simple message between two components

•Bundle - key/value data

•Limited payload size (500k)

•Inefficient for batch operations

•URI Support

Sunday, September 29, 13

Page 29: App to App: Design and Surface Local APIs

#EC2013

Intents: Android Standards

Sunday, September 29, 13

Page 30: App to App: Design and Surface Local APIs

#EC2013

Intents: Android Standards

•Intent.ACTION_SEND

Sunday, September 29, 13

Page 31: App to App: Design and Surface Local APIs

#EC2013

Intents: Android Standards

•Intent.ACTION_SEND

•Intent.EXTRA_STREAM

Sunday, September 29, 13

Page 32: App to App: Design and Surface Local APIs

#EC2013

Intents: Android Standards

•Intent.ACTION_SEND

•Intent.EXTRA_STREAM

•Intent.ACTION_VIEW

Sunday, September 29, 13

Page 33: App to App: Design and Surface Local APIs

#EC2013

Intents: Android Standards

•Intent.ACTION_SEND

•Intent.EXTRA_STREAM

•Intent.ACTION_VIEW

•Intent.ACTION_EDIT

Sunday, September 29, 13

Page 34: App to App: Design and Surface Local APIs

#EC2013

Intents: View And EDIT

Sunday, September 29, 13

Page 35: App to App: Design and Surface Local APIs

#EC2013

Intents: View And EDIT

•Set Action

Sunday, September 29, 13

Page 36: App to App: Design and Surface Local APIs

#EC2013

Intents: View And EDIT

•Set Action

•Data URI

Sunday, September 29, 13

Page 37: App to App: Design and Surface Local APIs

#EC2013

Intents: View And EDIT

•Set Action

•Data URI

•MIME Type

Sunday, September 29, 13

Page 38: App to App: Design and Surface Local APIs

#EC2013

Intents: View And EDIT

•Set Action

•Data URI

•MIME Type

•startActivity...ForResult()

Sunday, September 29, 13

Page 39: App to App: Design and Surface Local APIs

#EC2013

Intents: View And EDIT

•Set Action

•Data URI

•MIME Type

•startActivity...ForResult()

•onActivityResult()

Sunday, September 29, 13

Page 40: App to App: Design and Surface Local APIs

#EC2013

Intents: Evernote CRUD

gist.github.com/TylerSmithNet/6735496

Sunday, September 29, 13

Page 41: App to App: Design and Surface Local APIs

#EC2013

Intents: Evernote CRUD

public static final String NOTE_PICKER = "com.evernote.action.NOTE_PICKER"; public static final String VIEW_NOTE = "com.evernote.action.VIEW_NOTE";

public static final String NEW_NOTE = "com.evernote.action.CREATE_NEW_NOTE";  public static final String EDIT_NOTE = "com.evernote.action.EDIT_NOTE"; public static final String UPDATE_NOTE = "com.evernote.action.UPDATE_NOTE"; public static final String DELETE_NOTE = "com.evernote.action.DELETE_NOTE";

gist.github.com/TylerSmithNet/6735496

Sunday, September 29, 13

Page 42: App to App: Design and Surface Local APIs

#EC2013

Intents: New Note Overview

gist.github.com/TylerSmithNet/6735496

Sunday, September 29, 13

Page 43: App to App: Design and Surface Local APIs

#EC2013

Intents: New Note Overview

gist.github.com/TylerSmithNet/6735496

Sunday, September 29, 13

Page 44: App to App: Design and Surface Local APIs

#EC2013

Intents: New Note Overview

gist.github.com/TylerSmithNet/6735496

Sunday, September 29, 13

Page 45: App to App: Design and Surface Local APIs

#EC2013

Intents: New Note Overview

gist.github.com/TylerSmithNet/6735496

Sunday, September 29, 13

Page 46: App to App: Design and Surface Local APIs

#EC2013

Intents: New Note Overview

gist.github.com/TylerSmithNet/6735496

Sunday, September 29, 13

Page 47: App to App: Design and Surface Local APIs

#EC2013

Intents: New Note Overview

gist.github.com/TylerSmithNet/6735496

Sunday, September 29, 13

Page 48: App to App: Design and Surface Local APIs

#EC2013

Intents: New Note Overview

New Note Intent

gist.github.com/TylerSmithNet/6735496

Sunday, September 29, 13

Page 49: App to App: Design and Surface Local APIs

#EC2013

Intents: New Note Overview

New Note Intent

gist.github.com/TylerSmithNet/6735496

Sunday, September 29, 13

Page 50: App to App: Design and Surface Local APIs

#EC2013

Intents: New Note Overview

New Note Intent

gist.github.com/TylerSmithNet/6735496

Sunday, September 29, 13

Page 51: App to App: Design and Surface Local APIs

#EC2013

Intents: New Note Overview

New Note Intent

onActivityResult()

gist.github.com/TylerSmithNet/6735496

Sunday, September 29, 13

Page 52: App to App: Design and Surface Local APIs

#EC2013

Intents: Evernote New Note

gist.github.com/TylerSmithNet/6735496

Sunday, September 29, 13

Page 53: App to App: Design and Surface Local APIs

#EC2013

Intents: Evernote New Note

public static final String NEW_NOTE = "com.evernote.action.CREATE_NEW_NOTE";

public void newNoteWithContent(Uri image) {  String title = "Sample Title";  String text = "Sample description.";   Intent intent = new Intent();  intent.setAction(ACTION_NEW_NOTE);   // Set the note's title and plaintext content  intent.putExtra(Intent.EXTRA_TITLE, title);  intent.putExtra(Intent.EXTRA_TEXT, text); // Set the Data URI for the image intent.setData(image);  startActivityForResult(intent);}

gist.github.com/TylerSmithNet/6735496

Sunday, September 29, 13

Page 54: App to App: Design and Surface Local APIs

#EC2013

Content Provider

Sunday, September 29, 13

Page 55: App to App: Design and Surface Local APIs

#EC2013

Content Provider

•A well defined database access layer

Sunday, September 29, 13

Page 56: App to App: Design and Surface Local APIs

#EC2013

Content Provider

•A well defined database access layer

•SQLite

Sunday, September 29, 13

Page 57: App to App: Design and Surface Local APIs

#EC2013

Content Provider

•A well defined database access layer

•SQLite

•Interact with large volumes of data

Sunday, September 29, 13

Page 58: App to App: Design and Surface Local APIs

#EC2013

Content Provider

•A well defined database access layer

•SQLite

•Interact with large volumes of data

•Authority

Sunday, September 29, 13

Page 59: App to App: Design and Surface Local APIs

#EC2013

Content Provider

•A well defined database access layer

•SQLite

•Interact with large volumes of data

•Authority

•Permissions

Sunday, September 29, 13

Page 60: App to App: Design and Surface Local APIs

#EC2013

Content Provider: URI

content:// com.example / notes / 1

Sunday, September 29, 13

Page 61: App to App: Design and Surface Local APIs

#EC2013

Content Provider: URI

content:// com.example / notes / 1

Scheme

Sunday, September 29, 13

Page 62: App to App: Design and Surface Local APIs

#EC2013

Content Provider: URI

content:// com.example / notes / 1

Scheme Authority

Sunday, September 29, 13

Page 63: App to App: Design and Surface Local APIs

#EC2013

Content Provider: URI

content:// com.example / notes / 1

Scheme Authority Data Type

Sunday, September 29, 13

Page 64: App to App: Design and Surface Local APIs

#EC2013

Content Provider: URI

content:// com.example / notes / 1

Scheme Authority Data Type Id

Sunday, September 29, 13

Page 65: App to App: Design and Surface Local APIs

#EC2013

Content Provider: Implementing

Sunday, September 29, 13

Page 66: App to App: Design and Surface Local APIs

#EC2013

Content Provider: Implementing

•Override Methods

Sunday, September 29, 13

Page 67: App to App: Design and Surface Local APIs

#EC2013

Content Provider: Implementing

•Override Methods

•URI Matcher

Sunday, September 29, 13

Page 68: App to App: Design and Surface Local APIs

#EC2013

Content Provider: Implementing

•Override Methods

•URI Matcher

•Cursors

Sunday, September 29, 13

Page 69: App to App: Design and Surface Local APIs

#EC2013

Content Provider: Implementing

•Override Methods

•URI Matcher

•Cursors

•File Handlers

Sunday, September 29, 13

Page 70: App to App: Design and Surface Local APIs

#EC2013

Content Provider: Query

Sunday, September 29, 13

Page 71: App to App: Design and Surface Local APIs

#EC2013

Content Provider: Query

Uri authUri = Uri.parse("content://com.evernote.evernoteprovider"); Uri notesUri = Uri.withAppendedPath(authUri, "notes"); String[] projection = new String[]{"guid", "title"}; Cursor cursor = getContentResolver().query( notesUri, projection, null, null, null);

Sunday, September 29, 13

Page 72: App to App: Design and Surface Local APIs

#EC2013

Account Manager

Sunday, September 29, 13

Page 73: App to App: Design and Surface Local APIs

#EC2013

Account Manager

•Accessible Account

Sunday, September 29, 13

Page 74: App to App: Design and Surface Local APIs

#EC2013

Account Manager

•Accessible Account

•Third Party Auth

Sunday, September 29, 13

Page 75: App to App: Design and Surface Local APIs

#EC2013

Account Manager

•Accessible Account

•Third Party Auth

•Consistent Settings

Sunday, September 29, 13

Page 76: App to App: Design and Surface Local APIs

#EC2013

Account Manager: OAuth

Sunday, September 29, 13

Page 77: App to App: Design and Surface Local APIs

#EC2013

Account Manager: OAuth

Sunday, September 29, 13

Page 78: App to App: Design and Surface Local APIs

#EC2013

Account Manager: OAuth

Sunday, September 29, 13

Page 79: App to App: Design and Surface Local APIs

#EC2013

Account Manager: OAuth

Sunday, September 29, 13

Page 80: App to App: Design and Surface Local APIs

#EC2013

Account Manager: OAuth

Sunday, September 29, 13

Page 81: App to App: Design and Surface Local APIs

#EC2013

Account Manager: OAuth

Sunday, September 29, 13

Page 82: App to App: Design and Surface Local APIs

#EC2013

Account Manager: OAuth

getAuthToken(...)

Sunday, September 29, 13

Page 83: App to App: Design and Surface Local APIs

#EC2013

Account Manager: OAuth

getAuthToken(...)

Sunday, September 29, 13

Page 84: App to App: Design and Surface Local APIs

#EC2013

Account Manager: OAuth

getAuthToken(...)

Sunday, September 29, 13

Page 85: App to App: Design and Surface Local APIs

#EC2013

Account Manager: OAuth

getAuthToken(...)

Future<Bundle>

Sunday, September 29, 13

Page 86: App to App: Design and Surface Local APIs

#EC2013

Sync Adapter

Sunday, September 29, 13

Page 87: App to App: Design and Surface Local APIs

#EC2013

Sync Adapter

•Synchronizes App and Web Service

Sunday, September 29, 13

Page 88: App to App: Design and Surface Local APIs

#EC2013

Sync Adapter

•Synchronizes App and Web Service

•Network/battery optimized syncing

Sunday, September 29, 13

Page 89: App to App: Design and Surface Local APIs

#EC2013

Sync Adapter

•Synchronizes App and Web Service

•Network/battery optimized syncing

•Provided to third party apps

Sunday, September 29, 13

Page 90: App to App: Design and Surface Local APIs

#EC2013

Sync Adapter

•Synchronizes App and Web Service

•Network/battery optimized syncing

•Provided to third party apps

•Schedule and GCM

Sunday, September 29, 13

Page 91: App to App: Design and Surface Local APIs

#EC2013

Sync Adapter: Caveats

Sunday, September 29, 13

Page 92: App to App: Design and Surface Local APIs

#EC2013

Sync Adapter: Caveats

•Requires Content Provider and Account Manager

Sunday, September 29, 13

Page 93: App to App: Design and Surface Local APIs

#EC2013

Sync Adapter: Caveats

•Sync every hourContentResolver.addPeriodicSync(account, EvernoteContract.AUTHORITY, new Bundle(), 3600);

•Requires Content Provider and Account Manager

Sunday, September 29, 13

Page 94: App to App: Design and Surface Local APIs

#EC2013

Sync Adapter: Caveats

•Sync every hourContentResolver.addPeriodicSync(account, EvernoteContract.AUTHORITY, new Bundle(), 3600);

•Requires Content Provider and Account Manager

Sunday, September 29, 13

Page 95: App to App: Design and Surface Local APIs

#EC2013

Sync Adapter: Caveats

•Sync every hourContentResolver.addPeriodicSync(account, EvernoteContract.AUTHORITY, new Bundle(), 3600);

•Sync with Jitterint jitter = new Random().nextInt(300);

ContentResolver.addPeriodicSync(account, EvernoteContract.AUTHORITY, new Bundle(), 3600+jitter);

•Requires Content Provider and Account Manager

Sunday, September 29, 13

Page 96: App to App: Design and Surface Local APIs

#EC2013

Bound Service

Sunday, September 29, 13

Page 97: App to App: Design and Surface Local APIs

#EC2013

Bound Service

•Android Interface Definition Language (AIDL)

Sunday, September 29, 13

Page 98: App to App: Design and Surface Local APIs

#EC2013

Bound Service

•Android Interface Definition Language (AIDL)

•Directly call defined methods

Sunday, September 29, 13

Page 99: App to App: Design and Surface Local APIs

#EC2013

Bound Service

•Android Interface Definition Language (AIDL)

•Directly call defined methods

•Communicate between process or app

Sunday, September 29, 13

Page 100: App to App: Design and Surface Local APIs

#EC2013

Bound Service

•Android Interface Definition Language (AIDL)

•Directly call defined methods

•Communicate between process or app

•Requires consumer to contain interface

Sunday, September 29, 13

Page 101: App to App: Design and Surface Local APIs

#EC2013

Bound Service: Evernote and Dashclock

github.com/TylerSmithNet/EvernoteReminderDashclock

Sunday, September 29, 13

Page 102: App to App: Design and Surface Local APIs

#EC2013

Bound Service: Evernote and Dashclock

•Implements Dashclock jar (AIDL)

github.com/TylerSmithNet/EvernoteReminderDashclock

Sunday, September 29, 13

Page 103: App to App: Design and Surface Local APIs

#EC2013

Bound Service: Evernote and Dashclock

•Implements Dashclock jar (AIDL)

•Queries Evernote Content Provider

github.com/TylerSmithNet/EvernoteReminderDashclock

Sunday, September 29, 13

Page 104: App to App: Design and Surface Local APIs

#EC2013

Bound Service: Evernote and Dashclock

•Implements Dashclock jar (AIDL)

•Queries Evernote Content Provider

•Note list intent for clicks

github.com/TylerSmithNet/EvernoteReminderDashclock

Sunday, September 29, 13

Page 105: App to App: Design and Surface Local APIs

#EC2013

Bound Service: Evernote and Dashclock

•Implements Dashclock jar (AIDL)

•Queries Evernote Content Provider

•Note list intent for clicks

•Open Source

github.com/TylerSmithNet/EvernoteReminderDashclock

Sunday, September 29, 13

Page 106: App to App: Design and Surface Local APIs

#EC2013

Wrap up

Sunday, September 29, 13

Page 107: App to App: Design and Surface Local APIs

#EC2013

Wrap up

•Let the system do the work

Sunday, September 29, 13

Page 108: App to App: Design and Surface Local APIs

#EC2013

Wrap up

•Let the system do the work

•Base API design choice on user stories

Sunday, September 29, 13

Page 109: App to App: Design and Surface Local APIs

#EC2013

Wrap up

•Let the system do the work

•Base API design choice on user stories

•Give the user the best experience

Sunday, September 29, 13

Page 110: App to App: Design and Surface Local APIs

Ty SmithEvernote@tylersmithnet

Thanks, Questions?dev.evernote.com

Sunday, September 29, 13