I am developing a web application for university project, where an android client sends to a java server an image, and after that the server compares the image with those in the database and it has to send a response as a String object to the client who invoked the server. How can i do it? I use android-async-http to send the image from client and it works great, but i don't know how to send a response. This is a partial code of the client:
public void makeHTTPCall(){
prgDialog.setMessage("Server Connection..);
AsyncHttpClient client=new AsyncHttpClient();
client.post(ipAddress,params, new AsyncHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
prgDialog.hide();
Snackbar.make(parentLayout,"Image uploaded.",Snackbar.LENGTH_LONG).show();
}
@Override
public void onFailure(int statusCode, Header[] headers, byte[] responseBody, Throwable error) {
prgDialog.hide();
if(statusCode==404){
Snackbar.make(parentLayout,"Page not found.",Snackbar.LENGTH_LONG).show();
}
else if(statusCode==500){
Snackbar.make(parentLayout,"Server problem.",Snackbar.LENGTH_LONG).show();
}else{
Snackbar.make(parentLayout,"Generic Error. code: "+statusCode,Snackbar.LENGTH_LONG).show();
}
}
});
}
and here the code from server:
<%
String imgEncodedStr = request.getParameter("image");
String fileName = request.getParameter("filename");
System.out.println("Filename: "+ fileName);
if(imgEncodedStr != null){
ManipolaImmagini.stringToImage(imgEncodedStr, fileName);
System.out.println("Inside if");
out.print("Image upload complete, Please check your directory");
} else{
System.out.println("Inside else");
out.print("Image is empty");
}%>