when creating note in evernote how to attach PDF resource with note (android application)

603 Views Asked by At

when creating note in evernote how to attach PDF resource with note (android application).how to create resource list.

1

There are 1 best solutions below

0
On

Here is some sample code adapted from the ImagePicker sample found in Evernote's Android SDK which can be found in samples/HelloEDAM/src/com/evernote/android/sample/ImagePicker.java lines 197 to 228

Here is a link to the relevent file and line on Evernote's Github account where they host all their SDKs.

// Hash the data in the PDF file. The hash is used to reference the
// file in the ENML note content.
InputStream in = new BufferedInputStream(new FileInputStream(f));
FileData data = new FileData(EvernoteUtil.hash(in), new File(f));
in.close();

// Create a new Resource
Resource resource = new Resource();
resource.setData(data);
resource.setMime(mPDFdata.mimeType);
ResourceAttributes attributes = new ResourceAttributes();
attributes.setFileName(mPDFdata.fileName);
resource.setAttributes(attributes);

// Create a new Note
Note note = new Note();
note.setTitle("Android test note");
note.addToResources(resource);

// Set the note's ENML content. Learn about ENML at
// http://dev.evernote.com/documentation/cloud/chapters/ENML.php
String content =
    EvernoteUtil.NOTE_PREFIX +
        "<p>This note was uploaded from Android. It contains an PDF.</p>" +
        EvernoteUtil.createEnMediaTag(resource) +
        EvernoteUtil.NOTE_SUFFIX;

note.setContent(content);

if(!mEvernoteSession.getAuthenticationResult().isAppLinkedNotebook()) {
  // Create the note on the server. The returned Note object
  // will contain server-generated attributes such as the note's
  // unique ID (GUID), the Resource's GUID, and the creation and update time.

  mEvernoteSession.getClientFactory().createNoteStoreClient().createNote(note, mCreateImageCallback);
} else {
  super.createNoteInAppLinkedNotebook(note, mCreateImageCallback);
}