0

I'm trying to understand how I can send data from a web server to my android app. This isn't a request/receive type question, what I am looking to do is basically have my web server (say for example www.example.com/index.php) send a data (like a string for example) to my android app. Now, this data can be sent anytime, it isn't something where a you click something on the app to receive the data, but rather, when the server is wanting to send data, it sends the data, and my app picks it up. Now I'm not looking for my app to be listening for this data every second, an interval of 5 minutes or so is fine.

The question being, how would I achieve something like this? How can I send a string containing "Hello World" to my app? I know PHP, and I know this has to be done using POST/GET, and of course I know there will probably be some type of listener, service, or something of sort on the android side listening for this data, but I just want to know how I can approach this. What should my setup be?

If someone can provide some link or code to send a basic String message, then that would be more than enough for me to learn from.

3 Answers 3

1

There is two best approach you can follow.

  1. from server to app: in this case make corn job(timer service) which send push notification to android app. when app get push notification create one background service which download any data from server.

Note: if you have small text with limit of 100 char then no need to create service just send using push notification

  1. fetch data from server: in this case make one background service(auto start service) in android app. which run within some interval period like 1 hour or more(whatever your requirement). that service fetch data from server.(in this case android app eat battery of user device because of background service)

i will suggest you to use 1st approach because its easy and best way(in case of performance) your server do everything & android app have to just receive data.


how to implement push notification best tutorial using PHP & android(its old but just read official docs)

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, just one question. What does GCM require from the user of the app? Like, if the user opens the app, what would be absolutely mandatory for them to do?
user don't have to do any thing but you have to do some code(which generate unique key for device which is used to send push notification) on app side which receive push notification send by your server. try to understand diagram of this answer stackoverflow.com/a/16143572/1168654
0

For this you need implement android push notification.When you send the data from php server then the application get this data automatically.

2 Comments

How can I implement this?
Please check this androidhive.info/2012/10/… Here you will get details .How you will implement into android+PHP part
0

yes if you want to send data into your app from server side to app without calling web service on click of button you will use cronjob which run on defined time from server side(As i.e : if you want to run it every five seconds or minutes it will possible you don't need to call it from app side).

2 Comments

How would I do this? Say I have a button on my app that I click, and it starts a service which runs in the background, can I have that service listening for data from my web server (it checks every 5 minutes)? Will this be an ideal approach? How would I take this approach?
if you want to get data anytime you will implement push notification or you will implement web socket server using it you don't need to call server from your side every time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.