Passing images between Java client, Java server (with db sortage) and Android handset
I have created an application suite of three programs. The first program is a Java application that takes an image file and resizes it and creates an object with additional Strings for use in the Android client.
The second program is a Java servlet (RESTful services atm) that accepts uploads from the first program and stores the object into a database and then servers those objects to other Java applications and to Android handsets.
The third pro开发者_高级运维gram is an Android application that needs to download the objects from the server, save them to the SD card and then access them for use.
I wanted to just use RMI to pass the objects around the network but Android doesn't support RMI, so I started looking at XML-RPC and eventually decided to try RESTful services to act as the web controller for uploading and downloading. What I am having a problem with is figuring out how to encode my data.
One class has an ArrayList of objects that contain Strings.
One class has an image and a few Strings.
More classes will come with varying amounts of Strings and Images.
At the moment I am trying to use Gson to encode the objects into JSON but that doesn't seem to be working when I view the file, it can't handle the ArrayList. I am thinking about converting the images to Base64 strings to make the storage easier.
How should I be handling my data and what server could I be using? Ideally i would just like to get the data on the initial Java app and then just pass the objects around to the server and the other clients.
Thanks!
If you are doing XML RPC then you would have to encode image data to base64. You could also try using JSON RPC (as it would be a lot easier). That way ArrayList<String> would become a JSONArray ["string1","string2",..] and you can also throw image data into the mix using a structure like
{
"strings": ["string1","string2",...],
"imageData": "base64 encoded image data"
}
For more information on JSON you could take a look at the org.json package bundled with the Android SDK.
Have you considered using Atom Feeds and Entries? See http://www.ietf.org/rfc/rfc4287.txt
Atom is quite capable of handling lists of things and links to media objects like images.
精彩评论