How to create a server to communicate with an Android application

I need to create a server that initially checks the trial period for Android apps, so

  • When the Android application starts, information about the phones is sent to the server.
  • The server stores this information.
  • Whenever the application opens on this Android phone
  • the server checks if its trial period has passed or not expired.

In a way, it looks like a time bomb.

I am completely new to servers and just want a basic, secure server that simply registers the phone and compares it with a trial limit.

Does anyone have any info on how I can do this? Any code examples or tutorials are greatly appreciated.

+6
source share
2 answers

You did not specify your server technology, but in principle you need to do the following:

  • You probably want to open them as a REST web service. All you need is a GET operation to basically find out if the test has expired or not. Since you use Android and are familiar with Java, I suggest you look at JAX-RS , which is one way to implement REST in Java. If you are familiar with another language, then feel free to go for it.
  • The simplest form of your GET URL will probably look like http: // yoursite / getTrial / [beginTrialDate] , where [beginTrialDate] is the date in milliseconds since January 1, 1970 GMT (standard approach)
  • On the server side, you just took [beginTrialDate] and check if it exceeds your trial period by comparing the current time with [beginTrialDate] + [trial period]
  • You will then return a simple JSON response containing information about whether the application has expired. The simplest form: { "hasExpired" : true/false }

  • You would call this WebService on Android using HttpClient, as you probably already know. Check HTTP Client

  • You can make the server more reliable by storing the phone ID and your GET URL at http: // yoursite / getTrial / [phoneID] . The only additional difficulty is that you need to find the start date of the test by phoneID, and then compare it using step # 4

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

+3
source

The easiest way is to 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 the JSON code for your language choice.

I assume that you do not need a service to return a lot of data - perhaps a flag or minimal data. You can simply parse the JSON string that is returned to the device. If you have a lot of data to transfer, you can try some of the available JSON libraries.

0
source

Source: https://habr.com/ru/post/895514/


All Articles