The advantage of the first approach is that you have to do a minimum amount of work to push/pull notes and accompanying information from the Snaptic backend. The disadvantage is that you now have a dependency on 3banana notes which must be installed in order for you to access any stored information. Integrating using the Snaptic android-lib gets rid of this dependency and allows you to communicate directly with the backend. For instructions on how to integrate with 3banana notes using intents go here, the rest of this article will cover how to integrate using the Snaptic android-lib.
The following is a little cooking demo which will show you how to create a basic app which can post and fetch notes from a Snaptic account.
- Download the Snaptic android-lib project from git hub.
- Create a new Android project using the instructions outlined in the following hello world tutorial.
- Copy the src for com.android.http.multipart and com.snaptic.api into your project from Snaptic android-lib.
- Add the commons-codec-1.4.jar to your project (included in the android-lib lib directory), see this tutorial for instructions on how to add libraries with eclipse.
- Add the internet permission to your Hello World manifest xml file, for details on how to do this see here.
- Now add the following to your HelloAndroid activity in order to be able to post/get notes:
| Java | | copy code | | ? |
| 01 | |
| 02 | String LOGNAME = "HELLO_SNAPTIC"; |
| 03 | Boolean DEBUG = true; |
| 04 | String mUsername = "";//Add your username here |
| 05 | String mPassword = "";//Add your password here |
| 06 | SnapticAPI mApi = new SnapticAPI(mUsername, mPassword); |
| 07 | |
| 08 | //To post a note |
| 09 | |
| 10 | //Create a note |
| 11 | SnapticNote note = new SnapticNote(); |
| 12 | |
| 13 | //Set the attributes you cate about |
| 14 | note.text = "Post this notes"; |
| 15 | int returnCode = mApi.addNote(note); |
| 16 | |
| 17 | if(returnCode != SnapticAPI.RESULT_OK){ |
| 18 | //Log Error |
| 19 | if(DEBUG)Log.d(LOGNAME, "Notes Error: " + SnapticAPI.resultToString(returnCode)); |
| 20 | } |
| 21 | |
| 22 | //Grab all notes from the account. |
| 23 | |
| 24 | //Create an array list to hold notes |
| 25 | ArrayList<SnapticNote> notes = new ArrayList<SnapticNote>(); |
| 26 | |
| 27 | //Call get notes |
| 28 | returnCode = mApi.getNotes(notes); |
| 29 | |
| 30 | if(returnCode != SnapticAPI.RESULT_OK){ |
| 31 | //Log error |
| 32 | if(DEBUG)Log.d(LOGNAME, "Notes Error: " + SnapticAPI.resultToString(returnCode)); |
| 33 | } |
| 34 | |
| 35 | //Iterate over notes and do what you want with the note attributes |
| 36 | for(SnapticNote n : notes){ |
| 37 | if(DEBUG)Log.d(LOGNAME, "Note text" + n.text); |
| 38 | } |
| 39 |