Evernote SDK


Source link: https://github.com/evernote/evernote-sdk-android

Evernote SDK for Android version 2.0.0-RC4

Evernote API version 1.25

Overview

This SDK wraps the Evernote Cloud API and provides OAuth authentication functionality. The SDK is provided as an Android Library project that can be included in your application with Gradle.

Prerequisites

In order to use the code in this SDK, you need to obtain an API key from https://dev.evernote.com/doc/. You'll also find full API documentation on that page.

In order to run the demo code, you need a user account on the sandbox service where you will do your development. Sign up for an account at https://sandbox.evernote.com/Registration.action

The instructions below assume you have the latest Android SDK.

Download

Add the library as a dependency in your build.gradle file.

dependencies {

  compile 'com.evernote:android-sdk:2.0.0-RC4' 
}
(Optional) Using a snapshot build for early access previews

Add Sonatype's snapshot repository in your build script.

maven {

  url "https://oss.sonatype.org/content/repositories/snapshots" 
}

Add the snapshot depdendency.

dependencies {

  compile 'com.evernote:android-sdk:2.0.0-SNAPSHOT' 
}

Demo App

The demo application 'Evernote SDK Demo' demonstrates how to use the Evernote SDK for Android to authentication to the Evernote service using OAuth, then access the user's Evernote account. The demo code provides multiple activities that show notebook listing, note creation, and resource creation in two scenarios: A plain text note creator and an image saver.

Running the demo app from Android Studio

To build and run the demo project from Android Studio:

  1. Open Android Studio
  2. Choose Import Project (Eclipse ADT, Gradle, etc.)
  3. Select the SDK root directory (the directory containing this README) and click OK
  4. Add your Evernote API consumer key and secret (see below)
Adding Evernote API consumer key and secret

You have two different options to add your consumer key and secret.

gradle.properties file (preferred)
  1. Open the folder ~/.gradle in your user's home directory.
  2. Open or create a file called gradle.properties
  3. Add a line EVERNOTE_CONSUMER_KEY=Your Consumer Key
  4. Add a line EVERNOTE_CONSUMER_SECRET=Your Consumer Secret
In code
  1. Open the class com.evernote.android.demo.DemoApp.java
  2. At the top of DemoApp.java, fill in your Evernote API consumer key and secret.

Usage SDK

Modify your AndroidManifest.xml

The SDK's OAuth functionality is implemented as an Android Activity that must be declared in your app's AndroidManifest.xml.

Starting with Android Gradle plugin version 1.0.0 the necessary activities are merged in your app's AndroidManifest.xml file and you don't need to do anything. Otherwise simply copy and paste the following snippet into your AndroidManifest.xml within the application section:

<activity android:name="com.evernote.client.android.EvernoteOAuthActivity" /> <activity android:name="com.evernote.client.android.login.EvernoteLoginActivity"/>

Set up an EvernoteSession

Define your app credentials (key, secret, and host). See http://dev.evernote.com/documentation/cloud/

private static final String CONSUMER_KEY = "Your consumer key"; private static final String CONSUMER_SECRET = "Your consumer secret"; private static final EvernoteSession.EvernoteService EVERNOTE_SERVICE = EvernoteSession.EvernoteService.SANDBOX;

When your app starts, initialize the EvernoteSession singleton that has all of the information that is needed to authenticate to Evernote. The EvernoteSession instance of saved statically and does not need to be passed between activities. The better option is to build the instance in your onCreate() of the Application object or your parent Activity object.

mEvernoteSession = new EvernoteSession.Builder(this)
  .setEvernoteService(EVERNOTE_SERVICE)
  .setSupportAppLinkedNotebooks(SUPPORT_APP_LINKED_NOTEBOOKS)
  .build(consumerKey, consumerSecret)
  .asSingleton();

Give the user a way to initiate authentication

In our demo app, we have a "Login" button that initiates the authentication process. You might choose to do something similar, or you might simply initiate authentication the first time that the user tries to access Evernote-related functionality.

The recommended approach is to use FragmentActivitys. Then the authentication process opens a dialog and no extra Activity. But normal Activitys are supported as well.

mEvernoteSession.authenticate(this);

Evernote and Yinxiang Biji Service Bootstrapping

The Activity that completes the OAuth authentication automatically determines if the User is on the Evernote service or the Yinxiang service and configures the end points automatically.

If you want to test if bootstrapping works within your app, you can either change the device's language to Chinese or you can set a specific Locale object in the session builder, e.g. new EvernoteSession.Builder(this).setLocale(Locale.SIMPLIFIED_CHINESE). If the SDK can't decide which server to use, then the user has the option to change the Evernote service while authenticating.

Complete authentication

If you use a FragmentActivity, you should implement the EvernoteLoginFragment.ResultCallback interface.

public class MyActivity extends Activity implements EvernoteLoginFragment.ResultCallback {

// ...

@Override
  public void onLoginFinished(boolean successful) {

// handle result
  
}
 
}

 

If you use a normal Activity, you should override onActivityResult.

@Override public void onActivityResult(int requestCode, int resultCode, Intent data) {

  switch (requestCode) {

case EvernoteSession.REQUEST_CODE_LOGIN:

 if (resultCode == Activity.RESULT_OK) {

  // handle success

 
}
 else {

  // handle failure

 
}

break;

 default:

 super.onActivityResult(requestCode, resultCode, data);

 break;
  
}
 
}

Snippets

Calling EvernoteSession.getEvernoteClientFactory() will give you access to async wrappers around NoteStore.Client or UserStore.Client. Browse the API JavaDocs at http://dev.evernote.com/documentation/reference/javadoc/

The EvernoteClientFactory also creates multiple helper classes, e.g. EvernoteHtmlHelper to download a note as HTML.

Create an EvernoteNoteStoreClient to access primary methods for personal note data

EvernoteSession.getInstance().getEvernoteClientFactory().getNoteStoreClient();

Create an EvernoteUserStoreClient to access User related methods

EvernoteSession.getInstance().getEvernoteClientFactory().getUserStoreClient();

Create an EvernoteBusinessNotebookHelper to access Business Notebooks

EvernoteSession.getInstance().getEvernoteClientFactory().getBusinessNotebookHelper();

Create an EvernoteLinkedNotebookHelper to access shared notebooks

EvernoteSession.getInstance().getEvernoteClientFactory().getLinkedNotebookHelper(linkedNotebook);
Getting list of notebooks asynchronously
if (!EvernoteSession.getInstance().isLoggedIn()) {

  return; 
}
  EvernoteNoteStoreClient noteStoreClient = EvernoteSession.getInstance().getEvernoteClientFactory().getNoteStoreClient();
 noteStoreClient.listNotebooksAsync(new EvernoteCallback<List<Notebook>>() {

  @Override
  public void onSuccess(List<Notebook> result) {

List<String> namesList = new ArrayList<>(result.size());

for (Notebook notebook : result) {

 namesList.add(notebook.getName());

}

String notebookNames = TextUtils.join(", ", namesList);

Toast.makeText(getApplicationContext(), notebookNames + " notebooks have been retrieved", Toast.LENGTH_LONG).show();

  
}

@Override
  public void onException(Exception exception) {

Log.e(LOGTAG, "Error retrieving notebooks", exception);

  
}
 
}
);
Creating a note asynchronously
if (!EvernoteSession.getInstance().isLoggedIn()) {

  return; 
}
  EvernoteNoteStoreClient noteStoreClient = EvernoteSession.getInstance().getEvernoteClientFactory().getNoteStoreClient();
  Note note = new Note();
 note.setTitle("My title");
 note.setContent(EvernoteUtil.NOTE_PREFIX + "My content" + EvernoteUtil.NOTE_SUFFIX);
  noteStoreClient.createNoteAsync(note, new EvernoteCallback<Note>() {

  @Override
  public void onSuccess(Note result) {

Toast.makeText(getApplicationContext(), result.getTitle() + " has been created", Toast.LENGTH_LONG).show();

  
}

@Override
  public void onException(Exception exception) {

Log.e(LOGTAG, "Error creating note", exception);

  
}
 
}
);
Using the EvernoteBusinessNotebookHelper to Access Evernote Business data
  1. Check if user is member of a business
  2. Create EvernoteBusinessNotebookHelper
  3. Call synchronous methods from a background thread or call async methods from UI thread

This note store is not long lived, the Business authentication token expires frequently and is refreshed if needed in the getBusinessNotebookHelper() method.

Example using the synchronous business methods inside a background thread to create a note in a business account

new Thread() {

  @Override
  public void run() {

try {

 if (!EvernoteSession.getInstance().getEvernoteClientFactory().getUserStoreClient().isBusinessUser()) {

  Log.d(LOGTAG, "Not a business User");

  return;

 
}

  EvernoteBusinessNotebookHelper businessNotebookHelper = EvernoteSession.getInstance().getEvernoteClientFactory().getBusinessNotebookHelper();

 List<LinkedNotebook> businessNotebooks = businessNotebookHelper.listBusinessNotebooks(EvernoteSession.getInstance());

 if (businessNotebooks.isEmpty()) {

  Log.d(LOGTAG, "No business notebooks found");

 
}

  LinkedNotebook linkedNotebook = businessNotebooks.get(0);

  Note note = new Note();

 note.setTitle("My title");

 note.setContent(EvernoteUtil.NOTE_PREFIX + "My content" + EvernoteUtil.NOTE_SUFFIX);

  EvernoteLinkedNotebookHelper linkedNotebookHelper = EvernoteSession.getInstance().getEvernoteClientFactory().getLinkedNotebookHelper(linkedNotebook);

 final Note createdNote = linkedNotebookHelper.createNoteInLinkedNotebook(note);

  runOnUiThread(new Runnable() {

  @Override

  public void run() {

Toast.makeText(getApplicationContext(), createdNote.getTitle() + " has been created.", Toast.LENGTH_LONG).show();

  
}

 
}
);

 
}
 catch (TException | EDAMUserException | EDAMSystemException | EDAMNotFoundException e) {

 e.printStackTrace();

}

  
}
 
}
.start();
 

License

Copyright (c) 2007-2015 by Evernote Corporation, All rights reserved.  Use of the source code and binary libraries included in this package is permitted under the following terms:  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright
  notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright
  notice, this list of conditions and the following disclaimer in the
  documentation and/or other materials provided with the distribution.  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 

Resources

android-checkout is a library for Android In-App Billing (v3). The main goal is to reduce work which should be done by developers who want to integrate in-app purchases in their products. The project is inspired by Volley library and is designed to be easy to use, fast and flexible.

Mobile App testing on 300+ real devices!

  • Save in App Development Costs
  • Reduce Risks with Proactive, Agile Testing
  • Speed Up Time to Market
  • Reduce Operational & Unpredictable Costs
  • Improve App Ratings & Brand Reputation

AndroidAsync is a low level network protocol library.

Features:

  • Based on NIO. One thread, driven by callbacks. Highly efficient.
  • All operations return a Future that can be cancelled
  • Socket client + socket server
  • HTTP client + server
  • WebSocket client + server
  • Socket.IO client

This library is an Android networking abstraction library consisting of a combination of Volley, OkHttp, and Jackson, with a little glue to stick it all together. It's a great place to start if you need to execute requests, especially thos which return JSON.

RoboCoP is a Java library that can generate a fully-functional ContentProvider from a simple JSON schema file.

If you are looking for a listview with a paged header this is the dependency you are looking for. With PagedHeadListView you will be able to set your own fragments as new pages for the header, and a brand new indicator will be added automatically. You can play with all the custom attributes provided with the library to set indicator colors and position, ViewPager drag animation, and touch behaviour for the header view.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes