问题
Hello to all, I am trying to create android GCM without using server. I don't want to store. Because i don't have server.Is it possible?
If it's not possible then i want to store using WCF Service and MS SQL(Microsoft SQL). In online search all are given sample codes using PHP and MySQL. If any one know WCF service and MS SQL sample code means give me a refer.
Thanks in advance.
回答1:
To send push notifications, all you have to do is make a post request to
https://gcm-http.googleapis.com/gcm/send with autrhorization key in header and a json content in body.
for ex:
Content-Type:application/json
Authorization:key=LEFskdjfajskdfhaskjdhf....
{ "data": {
"message": "Hello world!!",
"time": "10:15"
},
"to" : "alsdkfjT0:EFHwgIpoDKCIZvvDMExUdFQ3P1....."
}
so what you have to do is:
- Create a project on Google Cloud Console. go to https://console.developers.google.com
- Among google APIs go to Google Cloud Messaging, and enable the api.
- After enabling go to credentials and create a Api key from there.
- Now you are ready for cloud messaging. All you need is the id of the clients whom you want to send to.
- This you will get from your android client by setting up the client there.
- Now you can even make this post request right from your computer on desktop application (with correct api key) to send a push notification to android client (you must know the client key).
I don't know how you will get the client ids if you don't have a server! However, you now know how to send that push, all you need is some mechanism to get that with some sort of webservice, WCF in your case.
you can also develop web apps for free on google app engine (based on quotas), in case you are looking to get a free server. Happy Coding!
来源:https://stackoverflow.com/questions/37138562/android-gcm-push-notification-without-server-or-gcm-push-notification-using-micr