Prak
Prak

Reputation: 175

Multiple GCM senders in the same app

I have used the below code to generate RegisterId for multiple sender ids.

public class RegistrationIntentService extends IntentService {
   @Override
   public void onHandleIntent(Intent intent) {
     InstanceID instanceID = InstanceID.getInstance(this);
     String senderIDs = "SENDER_ID_1,SENDER_ID_2";
     String token = instanceID.getToken(senderIDs, GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
     }
}

I referred this code from,

https://github.com/layerhq/documentation/blob/master/android/guides/push-integration.md

https://developer.layer.com/docs/android/guides

But i got "INVALID SENDER" exception.

Please help me to resolve this issue.

Upvotes: 2

Views: 189

Answers (1)

Android Enthusiast
Android Enthusiast

Reputation: 4950

GCM allows multiple parties to send messages to the same application.

For example, suppose your application is an articles aggregation with multiple contributors, and you want each of them to be able to send a message when they publish a new article. This message might contain a URL so that the application can download the article. Instead of having to centralize all sending activity in one location, GCM gives you the ability to let each of these contributors send its own messages.

To make this possible, all you need to do is have each sender generate its own project number. Then include those IDs in the sender field, separated by commas, when requesting a registration. Finally, share the registration ID with your partners, and they'll be able to send messages to your application using their own authentication keys.

This code snippet illustrates this feature. Senders are passed as an intent extra in a comma-separated list:

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);

Note that there is limit of 100 multiple senders.

You may check this doument for further information about multiple sender: https://stuff.mit.edu/afs/sipb/project/android/docs/google/gcm/demo.html

Upvotes: 2

Related Questions