Search code examples
androidhttpresponse

Return super simple JSON from regular Http


I have an Android app, and I want it to issue a notification at a certain time, which is decided by me.

So what I'd like to do, is program in the app for it to regularly make a request to some URL and if the response returns 1, to execute the notification in the app.

Can someone suggest a really simple way to set up a URL and response file? Or perhaps if you have a better way to do this, that would be great too.


Solution

  • Since you want to know when some event happens in the server (in your example, when response = 1), the best way to achieve this is through push notifications with Google Cloud Messaging (GCM).

    Instead of keep making connections from the device to the server to know when that response has become 1, the server will notify the device with a push when that condition (response == 1) is true. The device can then connect to the server to retrieve some information if needed.

    To get familiar with GCM start by reading the Google Cloud Messaging guide on Android Developer site. It has examples on how to implement the Android client side and the theory for the server side. Browsing the web you can easily find GCM example implementations for different languages. There are also services like Urban Airship if you don't feel like coding the GCM server by yourself.