Search code examples
androidevernote

How to create new notebook in evernote from android application?


I have referred this, I have integrated successfully, now I want to create Notebook from app for that I tried below code but I am getting every time exception.

 Note myNote = new Note();
 myNote.setTitle("My Test Notebook");                   
 createNoteInAppLinkedNotebook(myNote, new OnClientCallback<Note>() {
 @Override
 public void onSuccess(Note data) {
 }
 @Override
 public void onException(Exception exception) {
 Log.e(TAG, exception.toString());
  }
 }); 

@SuppressWarnings("deprecation")
protected void createNoteInAppLinkedNotebook(final Note note,final OnClientCallback<Note> createNoteCallback) {
    showDialog(DIALOG_PROGRESS);
    invokeOnAppLinkedNotebook(new OnClientCallback<Pair<AsyncLinkedNoteStoreClient, LinkedNotebook>>() {
        @Override
        public void onSuccess(
                final Pair<AsyncLinkedNoteStoreClient, LinkedNotebook> pair) {
            pair.first.createNoteAsync(note, pair.second,
                    createNoteCallback);
        }

        @Override
        public void onException(Exception exception) {
            Log.e(LOGTAG, "Error creating linked notestore", exception);
            Toast.makeText(getApplicationContext(),R.string.error_creating_notestore, Toast.LENGTH_LONG).show();
            removeDialog(DIALOG_PROGRESS);
        }
    });
}

I am getting Error creating linked notestore exception everytime.

Is there any solution for the same ?


Solution

  • Finally I found my own question's solution:

        Notebook nb = new Notebook();
        nb.setName("My Test Notebook");
    
        try {
            AsyncNoteStoreClient asyncNoteStoreClient = mEvernoteSession.getClientFactory().createNoteStoreClient();
            asyncNoteStoreClient.createNotebook(nb, new OnClientCallback<Notebook>() {
                @Override
                public void onSuccess(Notebook data) {
                    Log.i(TAG, "onSucceess");
                }
    
                @Override
                public void onException(Exception exception) {
                    Log.i(TAG, "onException");
    
                }
            });
        } catch (TTransportException e) {
            e.printStackTrace();
        }