4

I've a application deployed on google app-engine..it has a registration form. now i've made a registration form in my android application and i want that on click submit...it should be sent to the application on google app-engine and it should be persisted in the particular db...

somebody told me to use http request and response method but i'm not aware of that thing.. can somebody please provide me with some sample code or something.....

thanksss....

jasmeet
  • 43
  • 1
  • 3
  • 1
    This is very similar to your [other question](http://stackoverflow.com/questions/5933384/how-to-pass-parameters-from-android-apk-to-google-app-engine-deployed-code). Please do not duplicate questions, you can edit your older questions and retag them as you evolve your question. – Chris Farmiloe May 09 '11 at 10:26

1 Answers1

13

You haven't specified if you're using Python or Java.

You have to decide how you want to connect. At the simplest level you could just POST the data to Google App Engine. In Java you would write a servlet which handles this. See Java EE tutorial. Alternatively you could write a web service (SOAP, RESTful) on the server which handles the data being sent from your application. Again Google this and there are countless examples.

Assume we're going down the simplest POST route. So in your servlet (running on GAE) you'd have something like this:

public void doPost(HttpServletRequest request, 
        HttpServletResponse response) throws ServletException, IOException {

      String value1 = request.getParameter("value1");
}

And in your android app you'd do something like:

DefaultHttpClient hc=new DefaultHttpClient();
ResponseHandler <String> res=new BasicResponseHandler();
HttpPost postMethod=new HttpPost("http://mywebsite.com/mappedurl");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();  
nameValuePairs.add(new BasicNameValuePair("value1", "Value my user entered"));  
postMethod.setEntity(new UrlEncodedFormEntity(nameValuePairs));  
String response=hc.execute(postMethod,res);

Of course value1 in the servlet would be set to "Value my user entered".

EDIT: Google have now released their Google Cloud Endpoints - this makes building RESTful services on App Engine and creating clients for Android a lot easier. It does tie you in to App Engine even more though - but certainly worthy of consideration.

VHarisop
  • 2,816
  • 1
  • 14
  • 28
planetjones
  • 12,469
  • 5
  • 50
  • 51
  • I'm not going to write the whole thing, as you need to look around. However I've added basic code for the Servlet and Android app now. Please look at the Servlet tutorial for more info on how to configure servlets e.g. mapping the servlet to a url. – planetjones May 09 '11 at 09:40
  • if i have a jsp page on my GAE..then? – jasmeet May 09 '11 at 09:54
  • Well a JSP gets turned into a servlet, so yes you could put your code in there as scriptlets (not a nice way of doing things)... but yes the JSP could process the POST if you're after something quick and dirty. – planetjones May 09 '11 at 09:56