I am working on a sensor app in android and I've to store the accelerometer readings on a django server and then retrieve them on my device. I am new to django and I don't know how to communicate with Android's HttpClient and a django server.

2

There are 2 best solutions below

0
On

Django doesn't care what the client is, and Android's HttpClient don't care whether the url are served by Django, Tomcat, Rails, Apache or whatever. It's only HTTP. IOW:

  1. learn to write a Django App (it's fully documented)
  2. learn to use the Android's HttpClient (it's fully documented too IIRC)
  3. connect the dots...
0
On

I believe the simplest way is using Django Rest Framework.

In this scenario, the steps are:

  1. Install Django.
  2. Create the the Django App and the Model for the data you want to store and access through the API.
  3. Setup Django Rest Framework. There are many tutorials that can help you here, for example Getting Started with Django Rest Framework and AngularJS .
  4. Access your new API from a browser and your Django App. Here is going to be very useful the browser Django Rest Frameworks will automagically create for your API.

Unless you need to do something 'special', Django Rest Framework will help you a lot, generating views, dealing with JSon serialization and so on. Basically, the only thing you will need to care is the model definition.

From the Android side, you will need:

  1. Access your API using HttpClient. However, HttpClient library it is not recommended anymore to use it, as Google is focusing their efforts on improving the HttpURLConnection implementation.

  2. Parser the data you got, in this in JSon format. To do this, you can use JsonReader.

Another alternative is using Retrofit, a very popular REST client for Android and Java, which solves the two problems very easily.