Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send data from Android mobile devices to the Google App Engine datastore?

I need to write an application that sends data to the Google App Engine from Android. The data that I would like to send can be described by a typical database record. Each record has some integers, strings, dates, etc. I would like to keep the connection details hidden/secured so that someone can't create false data in the datastore, if it it's not too involved.

My question is: what is a good way to get this data from Android devices into the GAE datastore? If you could post a link to the appropriate Android libraries, or a link to how this has been done in the past, that would be really helpful.

like image 999
Doughy Avatar asked Dec 31 '09 05:12

Doughy


2 Answers

Nothing Android-specific about this -- just send an HTTP POST to a GAE-served URL that will accept the request, process it, and store your data. There's no "Android-GAE" royal road -- a POST is just the normal way to perform this, whoever's sending it, whoever's serving it!

like image 84
Alex Martelli Avatar answered Sep 21 '22 05:09

Alex Martelli


Yep, just send an http post. Here's a snippet of some code I used that worked fine on Android.

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ByteArrayEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;

    try {
        int TIMEOUT_MILLISEC = 10000;  // = 10 seconds
        HttpParams httpParams = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(httpParams,
                                                  TIMEOUT_MILLISEC);
        HttpConnectionParams.setSoTimeout(httpParams, TIMEOUT_MILLISEC);
        HttpClient client = new DefaultHttpClient(httpParams);

        HttpPost request = new HttpPost(serverUrl);
        request.setEntity(new ByteArrayEntity(
            postMessage.toString().getBytes("UTF8")));

        HttpResponse response = client.execute(request);
    } catch (Exception e) {
        ....
    }
like image 42
dmazzoni Avatar answered Sep 19 '22 05:09

dmazzoni