Push notification using GCM with ASP.NET server in

2019-06-08 07:47发布

问题:

Having some of the queries....

final String regId = GCMRegistrar.getRegistrationId(this);               // MainActivity.java class

By this statement I am receiving registration id dynamically for devices running this application and thus sending to the web server. But as you said in addition to send any other identifying factor (user id or phone id) to the webserver. How to get and send those ids dynamically.

List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
 for (int i = 0; i < Vars.length; i++) {
            nameValuePairs.add(new BasicNameValuePair(Vars[i][0], Vars[i][1]));

How to set the array dimension dynamically, because depending upon the registered devices, I am setting the array of registration id for all those registered devices and sending that to web server. Please paste your OnRegistered & UnRegistered Method of the GCMIntentService class.

Also how in the server side .net developer will send that array of data to GCM server. Now he is sending registration id in json format for multiple devices, but it is not executing. We are getting 404 error or Bad request. For single registration id using this below statement it is executing in the server side.

string postData = "collapse_key=score_update&time_to_live=108&delay_while_idle=1&data.message=" + value + "&data.time=" + System.DateTime.Now.ToString() + "&registration_id=" + deviceIDs + "";

Please let me know if any other id has to be passed. Because what confuse me that an application can be installed by more than 1000+ users. Is it efficient to store those many ids in the database??? Because our server has to send those many ids to GCM server, else everyone will not receive the push notification.

回答1:

If you are only going to send to every person with the app then you do not need to store any other information other than the GCM ID. however if you don't store them individually you will eventually have IDs that are no longer valid. Sometimes phones get new ids and if you store them in 1 record then you will not know how which ids have changed

the nameValuePairs List will hold the values of the form request. such as gcmid, OtherUniquePhoneInfo and whatever else you would like to send. If you are storing all GCM Ids in 1 record then you only have to send the GCM Id. You only have to add 1 field to the nameValuePairs List

If you want to send to all the devices that have your app then you have to send every ID to the GCM server.



回答2:

Registration ids are changed periodically.i agree with zhydian ids will no longer be valid.

for identifying device you can use unique device no.