API

Evernote SDK for Android v1.1 – Asynchronous API Wrappers, Business & China Support

Posted by Ty Smith on 15 Mar 2013

Posted by Ty Smith on 15 Mar 2013

Comment

Evernote SDK for Android

Since the 1.0 release of our Android SDK, we’ve gotten quite a bit of feedback from the community and we’ve been hard at work to make the SDK much easier to use. In this release we’ve added enhanced developer tools and improved the OAuth flow to include automatic Evernote China service selection.

Improving the Android SDK

The main goal of the 1.1 release was to simplify the full Evernote API by providing easy access to the China service YXBJ, business notebooks, and linked notebooks. We also introduced an easy to use asynchronous interface to multithread the Evernote network requests.

The full list of features:

  • Asynchronous wrappers around NoteStore.Client and UserStore.Client
  • Helper objects to work with Business Notebooks and Linked Notebooks
  • Added a ClientFactory to assist creating the various Client objects
  • Automatic Evernote China service selection during login
  • Simplified the singleton initialization process
  • Added sample code that includes note creation, resource creation, notebook selection as well as working with multiple activities
  • Bug fixes

Here’s an example of listing notebooks using the new AsyncNoteStoreClient and the new OnClientCallback interface

These two examples show different ways of listing notebooks: personal notebooks and business notebooks.


ClientFactory clientFactory = mEvernoteSession.getClientFactory()
  .getNoteStoreClient();

client.listNotebooks(new OnClientCallback<List() {
  @Override
  public void onSuccess(final List notebooks) {
    //This is running in the UI Thread
    Log.d(LOGTAG, "Notebook count="notebooks.size());
  }

  @Override
  public void onException(Exception exception) {
    //This is running in the UI Thread    
    Log.e(LOGTAG, "Error listing notebooks", exception);
  }
});

The first example creates an AsyncNoteStoreClient and uses that to call listNotebooks providing an OnClientCallback. This will run the network operation in a background thread and return the results to the UI thread.


mEvernoteSession.getClientFactory().createBusinessNoteStoreClient(
   new OnClientCallback() {

   @Override
  public void onSuccess(final AsyncBusinessNoteStoreClient client) {
    //This is running in the UI Thread    
    client.listNotebooks(new OnClientCallback<List() {
      @Override
      public void onSuccess(final List notebooks) {
        //This is running in the UI Thread
        Log.d(LOGTAG, "Notebook count="notebooks.size());
      }

      @Override
      public void onException(Exception exception) {
         //This is running in the UI Thread
        Log.e(LOGTAG, "Error listing notebooks", exception);
      }
    }
  });

  @Override
  public void onException(Exception exception) {
    Log.e(LOGTAG, "Error create business note store", exception);
  }
});

The second example creates an AsyncBusinessNoteStoreClient using an OnClientCallback and then uses the result to call listNotebooks providing a second OnClientCallback. This will run the network operation in a background thread and return the results to the UI thread. This nested callbacks are required as both createBusinessNoteStore and listNotebooks are dependent network requests. The createBusinessNoteStoreClient method will authorize a new token for the business account if needed.

If direct access to the NoteStore.Client object is needed, a call to AsyncNoteStoreClient.getClient() will produce it. All calls on this object are synchronous though, so a developer would need to manage their own background threading operations.

Installing the SDK


<dependency>
    <groupId>com.evernote</groupId>
    <artifactId>android-sdk</artifactId>
    <version>1.1</version>
    <type>apklib</type>
</dependency>

If you are using Maven, just add the dependency to your pom.xml. If you are manually installing the library, go to our Github page for instructions.

As Evernote Business grows, it’s going to be more important for your application to work with all of the users’ data. These utilities should help you do just that. New sample code has been added to cover many of these features. Feel free to browse the Github repository and contribute using pull requests or issues. As always, we are here to support you, so reach out on the Evernote Developer Forums with any questions.

We hope this update will make integrating your Android app with Evernote much easier.

About Ty:

Ty Smith Android EngineerTy Smith is a Sr. Android Engineer on the Evernote product team. In addition to working on the core Evernote client, Ty maintains the Android SDK on Github and supports our developer community.

Prior to Evernote, Ty was the lead engineer on Powow Text Messaging and Zagat for Android (before the Google acquisition) at One Louder Apps.

@tylersmithnettsmith@evernote.com

View more stories in 'API'