Regarding GCM from multiple applications

跟風遠走 提交于 2019-12-11 08:12:51

问题


Hi I had used C2DM in my application to push messages. Now I have migrated to GCM and through it I can push messages to android application.

More over there's one feature of GCM , through which two or more server applications can push messages to android application. How this feature can be implemented. For exaemple I have a news feed application from one provider. Now along with the news updates some third party local offers vendors can also push the offers updates.

Thanks


回答1:


After creating google Api project for Gcm you will get the id for your project.

This id is unique for your project (and you can use this in many of your application).

Using this project id you can register your device to GCM;after registering successfully on Gcm,Gcm will return you an registration id(also called as PUSH_TOKEN).

using this registration id and project id, many server can send notification to device.

to receive the notification from server you need to implement GCMIntentService class.

and you will receive your messages in onMessage(Context arg0, Intent arg1) method.

I strongly recommend you to have a look at Getting started with GCM

Document also says that,Gcm allows multiple sender are passed as an intent extra in a comma-separated list As,

Intent intent = new Intent(GCMConstants.INTENT_TO_GCM_REGISTRATION);
intent.setPackage(GSF_PACKAGE);
intent.putExtra(GCMConstants.EXTRA_APPLICATION_PENDING_INTENT,
PendingIntent.getBroadcast(context, 0, new Intent(), 0));
String senderIds = "968350041068,652183961211";
intent.putExtra(GCMConstants.EXTRA_SENDER, senderIds);
ontext.startService(intent);


来源:https://stackoverflow.com/questions/14049239/regarding-gcm-from-multiple-applications

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!