/AndroidJSONHandler

Android json Handler is a library for Android, which make it easy to communicate with JSON api's on webservers.

Android JSON Handler

====================

Introduction:

Android json Handler is a library for Android, which make it easy to communicate with JSON api's on webservers.
The library extends the AsyncTask Android class, so it will work asynchronously with your code and not stop the whole exicution of your program.
You can define the different dialog messages, using different methods in the the class.
The class is written for own use, so don't expect it to be perfectly written an documentet :)

How to install the library:

  1. Download Apache HttpClient binaries, and import the "/lib/httpmime-4.2.1.jar" into your "libs" folder in your Android Project. Add the "httpmime-4.2.1.jar" to your build path(see properties for project in Eclipse).
  2. Download AndroidJSONHandler, and import the "dk" folder(with subfolders) into your "src" folder.

How to use:

  1. Create a new JSONHandler object, and insert the context as parameter.
  2. If you want to upload a file, use the method .setNameOfFileField(fieldname) to set which field contains the file.
  3. Use .setDiag(tittle, message) method, to set which text should be shown while the request is made.
  4. Error message is default set to be shown! If an error accurs, the callback will not be called and an error message will be shown to the user.
    The text of this error message can be set using .setErrMsg(tittle, message).
    If you do not want the error message to appear, and the callback to be called even if an error happens, use the .showErrMsg(false) to disable the error message. The callback will then be called with the last parameter set to true, if an error has occurred.
  5. Use the method .makeRequest(String url, List parameters, String method, String callback).
    The method takes four parameters as input:
    • String url: The URL which should be called(ex. http://kasperbaago.dk/api/)
    • List parameters: Set which parameters should be send with the call?(ex. POST and GET parameters)
      This is made using a list of nameValuePairs, where name is the key and value is the value of the reqest.
      You can then use ether $_POST[name] or $_GET[name] in PHP to get the values send with the request.
    • String method: Which method that should be used to make the call("post" or "get").
    • String callback: The method that should be called with the result of your request to the server.
      This method will be called with two parameters: The first is a JSONArray, containing the returned JSON data. The last is a boolean value, which is true if an error has occurred during exicution.
  6. The method .getHTML() can be used to return the clear text HTML of the callback. This is usefull when debuging.

Example:

You can check out my example of using the library here.