Philip
Philip

Reputation: 1078

Send "something" to a Device that has my app installed?

when a certain condition is true, I need to send a message to a certain device that has my app installed. How can I realize it? E.g. A klicks on the name B, B shall get an AlertDialog that A clicked on his name. I know that I will need something like a deviceID. But what else?

Upvotes: 1

Views: 67

Answers (3)

user3432220
user3432220

Reputation: 101

You need to poll the app you want to send something to.

Upvotes: 0

scottt
scottt

Reputation: 8371

If the recipient device currently has your app running and is connected, then the app you would presumably maintain a connection to a server or implement polling by the app.

For a non-running recipient app, you'll either have to utilize a standard messaging protocol (SMS, email, etc.). Or you will have to implement a background service in your app that periodically wakes up and polls a server that maintains the messages. This is how Twitter, Facebook, etc. work.

Just to be clear, opening or maintaining direct network connections between multiple devices not on the same local network is not really doable.

Upvotes: 1

Merlevede
Merlevede

Reputation: 8170

You don't need a device ID, you need a server that handles the communiation between the two devices.

In order for a device (A) to communicate directly to another device (B) without a server, A needs to know who B is and how to reach it.

  • You could do that either with an SMS and the only thing you need to know about B is its phone number, but I guess this is not what you want to hear.
  • The other options is through a TCP/IP network. A would need to know B's IP address, which is something almost unfeasible, unless both devices are connected to the same network, probably via WiFi, and even so, there's no direct way to know B's address.

The usual solution is that both devices connect to a server through the network, using a particular protocol. When A want's to send a message to B, it does it through the server, which forward the request to B (since B is also connected to the server). In order to identify the devices you can use any information bit you want (it can be a user name, such as in chat systems, it can be the device ID which is not very reliable...)

Upvotes: 1

Related Questions