Pregunta

I have cloud database so I have all device's reg ID's.

Do I have to use a server for sending message ? Can I send message directly from one Android device to another just using regID ? Can I use Android device as server ?

¿Fue útil?

Solución

If each Android device has access to the database of registration IDs, it can send GCM messages to other devices without using a server. You simply have to execute the same HTTP request to GCM that you would normally do from a server. That request would go directly to GCM server and from there would be delivered to your app on another device. To execute that request you need your app to know both the sender ID (for registering to GCM) and the API key (for sending messages) in addition to the recipient registration ID.

You can't use the gcm.send method. That method sends messages to your server.

Otros consejos

Yes you can send a message to your server:

data.putString("my_message", "Hello World");
data.putString("my_action", "com.google.android.gcm.demo.app.ECHO_NOW");
String id = Integer.toString(msgId.incrementAndGet());
gcm.send(SENDER_ID + "@gcm.googleapis.com", id, data);

You can's send a message directly to other device because only Google's servers know where the receiver device is. The scheme of messaging looks like this:

Sender > Google's server > Your server > Google's server > Receiver

Theoretically you can add receiver's id to the sending data, get it on your server and then send new message to the concrete device.

You can find more detailed description in the documentation

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top