user1163278
user1163278

Reputation: 421

Android server request listener

I'm trying to find a solution to listening for a request from a server. The server would send a String to the phone, based on the ip address of the phone and the android app would take action when it happens.

Has anybody here faced a simular problem and can direct me to an example on the web or something?

Thanks

Upvotes: 2

Views: 2621

Answers (2)

Nikolay Elenkov
Nikolay Elenkov

Reputation: 52956

You can't really be sure of a mobile device's IP address. It can change as you switch between WiFi hotspots, or as you move to a different 3G area. For this to work, the mobile has to register somehow with the server. The usual way to implement it is to keep an open connection, where the server responds with data only when it wants to notify the client. It is possible to create your own implementation, but not trivial. Android has a standard way to do this called Cloud to Device Messaging (C2DM). It is used by GMail and other Google apps, so it's fairly reliable. There are other services that provide something similar, you might want to look into those if C2DM doesn't fit your needs (it requires a Google account, etc.)

Upvotes: 1

Ikrom
Ikrom

Reputation: 5123

You can use sockets for it. See here and here.

Upvotes: 2

Related Questions