问题
I want to know whether it is possible for sending a notification from one android mobile to android mobile via a local server?
回答1:
You don't need a server.
Send: Your phone can perform a HTTP POST to Google's servers of some JSON describing the sender/registration ids (along with the message), which then passes the message to the target device(s). Details here: http://developer.android.com/google/gcm/c2dm.html
Note that that page describes migration from C2DM to GCM. What i'm suggesting here is the new GCM method. Base your JSON on the last example on that page:
Content-Type:application/json
Authorization:key=AIzaSyB-1uEai2WiUapxCs2Q0GZYzPu7Udno5aA
{
"registration_id" : "APA91bHun4MxP5egoKMwt2KZFBaFUH-1RYqx...",
"data" : {
"Team" : "Portugal",
"Score" : "3",
"Player" : "Varela",
},
}
Receive: using Google's GCM system to receive via intents as described here: http://developer.android.com/google/gcm/client.html
回答2:
I want to know whether it is possible for sending a message from one android mobile to another using GCM ?
Yes , it is possible.
Can android mobile act as server to post message via GCM?
No , You will need to use 3rd party server to communicate between two mobile phones.
Full information is available here.
来源:https://stackoverflow.com/questions/20901597/send-message-using-gcm