How to create a server for communication with an Android app [closed]
Asked Answered
P

2

7

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.

Provoke answered 21/8, 2011 at 3:55 Comment(1)
Try this link. It may help you.Overrun
S
3

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

Splenetic answered 21/8, 2011 at 4:12 Comment(2)
Hey, thank you very much for your reply, just so you know im very much a beginner, therefore most of what you said above im not familiar with, is there any sort of tutorial or read up to help me build knoweldge on how to carry the method provided above?? Thanks anywayProvoke
I've added the links in the answer. Here are concepts that you need to get going REST-API to build the webservice, JSON as a data format, and HttpClient to call the service from AndroidSplenetic
O
0

Easiest way would be write a JSON service. here is a link to a sample PHP JSON service - http://davidwalsh.name/web-service-php-mysql-xml-json You can easily find JSON code for your choice of language.

I'm guessing that you dont need the service to return lot of data - probably a flag or minimal data. You could simply parse through the JSON string that is returned to the device. If you have lot of data to be passed, you could try some free JSON libraries available

Onega answered 21/8, 2011 at 4:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.