* Create a new note containing a little text and the Evernote icon.
*/
private void createNote() throws Exception {
// To create a new note, simply create a new Note object and fill in
// attributes such as the note's title.
Note note = new Note();
note.setTitle("Test note from EDAMDemo.java");
String fileName = "enlogo.png";
String mimeType = "image/png";
// To include an attachment such as an image in a note, first create a
// Resource
// for the attachment. At a minimum, the Resource contains the binary
// attachment
// data, an MD5 hash of the binary data, and the attachment MIME type.
// It can also
// include attributes such as filename and location.
Resource resource = new Resource();
resource.setData(readFileAsData(fileName));
resource.setMime(mimeType);
ResourceAttributes attributes = new ResourceAttributes();
attributes.setFileName(fileName);
resource.setAttributes(attributes);
// Now, add the new Resource to the note's list of resources
note.addToResources(resource);
// To display the Resource as part of the note's content, include an
// <en-media>
// tag in the note's ENML content. The en-media tag identifies the
// corresponding
// Resource using the MD5 hash.
String hashHex = bytesToHex(resource.getData().getBodyHash());
// The content of an Evernote note is represented using Evernote Markup
// Language
// (ENML). The full ENML specification can be found in the Evernote API
// Overview
// at http://dev.evernote.com/documentation/cloud/chapters/ENML.php
String content = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ "<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">"
+ "<en-note>"
+ "<span style=\"color:green;\">Here's the Evernote logo:</span><br/>"
+ "<en-media type=\"image/png\" hash=\"" + hashHex + "\"/>"
+ "</en-note>";
note.setContent(content);
// Finally, send the new note to Evernote using the createNote method
// The new Note object that is returned will contain server-generated
// attributes such as the new note's unique GUID.
Note createdNote = noteStore.createNote(note);
newNoteGuid = createdNote.getGuid();
System.out.println("Successfully created a new note with GUID: "
+ newNoteGuid);
System.out.println();
}