public class

EvernoteSession

extends Object
java.lang.Object
   ↳ com.evernote.client.android.EvernoteSession

Class Overview

Represents a session with the Evernote web service API. Used to authenticate to the service via OAuth and obtain NoteStore.Client objects, which are used to make authenticated API calls. To use EvernoteSession, first initialize the EvernoteSession singleton and initiate authentication at an appropriate time:

   EvernoteSession session = EvernoteSession.init(...);
   if (!session.isLoggedIn()) {
     session.authenticate(...);
   }
 
When authentication completes, you will want to trap the result in onActivityResult to see if it was successful:
   public void onActivityResult(int requestCode, int resultCode, Intent data) {
     super.onActivityResult(requestCode, resultCode, data);
       switch(requestCode) {
       case EvernoteSession.REQUEST_CODE_OAUTH:
         if (resultCode == Activity.RESULT_OK) {
           // OAuth login was successful, do the appropriate thing for your app
         }
         break;
     }
   }
 
Later, you can make any Evernote API calls that you need by obtaining a NoteStore.Client from the session and using the session's auth token:
   NoteStore.client noteStore = session.createNoteStoreClient();
   Notebook notebook = noteStore.getDefaultNotebook(session.getAuthToken());
 
class created by @tylersmithnet

Summary

Nested Classes
enum EvernoteSession.EvernoteService Evernote Service to use with the bootstrap profile detection. 
Constants
String HOST_CHINA
String HOST_PRODUCTION
String HOST_SANDBOX
int REQUEST_CODE_OAUTH
Public Methods
void authenticate(Context ctx)
Start the OAuth authentication process.
String getAuthToken()
Get the authentication token that is used to make API calls though a NoteStore.Client.
AuthenticationResult getAuthenticationResult()
Get the authentication information returned by a successful OAuth authentication to the Evernote web service.
ClientFactory getClientFactory()
static EvernoteSession getInstance(Context ctx, String consumerKey, String consumerSecret, EvernoteSession.EvernoteService evernoteService)
Use to acquire a singleton instance of the EvernoteSession for authentication.
boolean isLoggedIn()
Check whether the session has valid authentication information that will allow successful API calls to be made.
void logOut(Context ctx)
Clear all stored authentication information.
Protected Methods
BootstrapManager getBootstrapSession()
boolean persistAuthenticationToken(Context ctx, EvernoteAuthToken authToken, String evernoteHost)
Called upon completion of the OAuth process to save resulting authentication information into the application's SharedPreferences, allowing it to be reused later.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final String HOST_CHINA

Constant Value: "https://app.yinxiang.com"

public static final String HOST_PRODUCTION

Constant Value: "https://www.evernote.com"

public static final String HOST_SANDBOX

Constant Value: "https://sandbox.evernote.com"

public static final int REQUEST_CODE_OAUTH

Constant Value: 14390 (0x00003836)

Public Methods

public void authenticate (Context ctx)

Start the OAuth authentication process. TODO do we need to do anything special here if you're already logged in?

public String getAuthToken ()

Get the authentication token that is used to make API calls though a NoteStore.Client.

Returns
  • the authentication token, or null if isLoggedIn() is false.

public AuthenticationResult getAuthenticationResult ()

Get the authentication information returned by a successful OAuth authentication to the Evernote web service.

public ClientFactory getClientFactory ()

public static EvernoteSession getInstance (Context ctx, String consumerKey, String consumerSecret, EvernoteSession.EvernoteService evernoteService)

Use to acquire a singleton instance of the EvernoteSession for authentication. If the singleton has already been initialized, the existing instance will be returned (and the parameters passed to this method will be ignored).

Parameters
consumerKey The consumer key portion of your application's API key.
consumerSecret The consumer secret portion of your application's API key.
evernoteService The enum of the Evernote service instance that you wish to use. Development and testing is typically performed against SANDBOX. The production Evernote service is HOST_PRODUCTION.
Returns
  • The EvernoteSession singleton instance.
Throws
IllegalArgumentException

public boolean isLoggedIn ()

Check whether the session has valid authentication information that will allow successful API calls to be made.

public void logOut (Context ctx)

Clear all stored authentication information.

Protected Methods

protected BootstrapManager getBootstrapSession ()

Returns
  • the Bootstrap object to check for server host urls

protected boolean persistAuthenticationToken (Context ctx, EvernoteAuthToken authToken, String evernoteHost)

Called upon completion of the OAuth process to save resulting authentication information into the application's SharedPreferences, allowing it to be reused later.

Parameters
ctx Application Context or activity
authToken The authentication information returned at the end of a successful OAuth authentication.
evernoteHost the URL of the Evernote Web API to connect to, provided by the bootstrap results