Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i connect a google app-engine application with my android?

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....

like image 921
jasmeet Avatar asked Dec 13 '22 13:12

jasmeet


1 Answers

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.

like image 159
planetjones Avatar answered May 22 '23 12:05

planetjones