How to create a server for communication with an Android app

asd2005 picture asd2005 · Aug 21, 2011 · Viewed 15.9k times · Source

I need to create a server which initially checks an Android applications trial period, so

  • on running an Android application the phones info is sent over to ther server.
  • The server stores this information.
  • Whenever the application is opened within that android phone
  • the server checks its trial period has or has not expired.

In a way it's like an Android time bomb.

I'm completely new to servers and really just want a basic, secure, server that simply registers a phone and compares it against a trial limit.

Anyone have any information on how I could do this? Any code examples or tutorials are very much appreciated.

Answer

momo picture momo · Aug 21, 2011

You didn't specify your server technology, but in principal you need to do the following:

  1. You probably want to expose them as a REST Webservice. All you need is a GET operation to basically figure out if the trial has expired or not. Since you are using Android and have gained familiarity with Java, I suggest you look at JAX-RS which is one way to implement REST in Java. If you are familiar with other language, then feel free to go for that.
  2. The simplest form of your GET URL would probably look like http://yoursite/getTrial/[beginTrialDate] where [beginTrialDate] is a date in millis since Jan 1, 1970 GMT (standard approach)
  3. On the server side, you simply took the [beginTrialDate] and check if it has exceed your trial period by comparing current time to [beginTrialDate] + [trial period]
  4. You would then return a simple JSON response containing the information whether the app has expired or not. The simplest form would be: { "hasExpired" : true/false }

  5. You would call this WebService in Android using HttpClient as you would probably know already. Check this HTTP Client Tutorial

  6. You could make the server more robust by storing the phone identifier and your GET URL change to http://yoursite/getTrial/[phoneID]. The only additional complexity is you have to look up the begin trial date by phoneID and then compare it again using the step #4

Let me know if you need more clarification and I will add it to the post