Search code examples
androidandroid-c2dm

Android C2DM in different environments (staging, production, debug)


I have the problem that I'm receiving all the notifications in all the environments. All the builds have currently the same package name. So only one build can be installed on the device at the same time. But I get then notifications targeting all builds (can be the correct one or one of the others).

I looked in the registration id and it's always the same. The problem is probably that all the apps share the same package name?

The parameters I see for registeration are:

  1. Broadcast receiver in the manifest:

    <receiver android:name="com.google.android.c2dm.C2DMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND">
        <intent-filter>
          <action android:name="com.google.android.c2dm.intent.RECEIVE" />
          <category android:name="com.company.product" />
        </intent-filter>
        <intent-filter>
          <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
          <category android:name="com.company.product" />
      </intent-filter>
    </receiver>
    
  2. Permissions:

    <permission android:name="com.company.product.permission.C2D_MESSAGE"
    android:protectionLevel="signature"/> <uses-permission android:name="com.company.product.permission.C2D_MESSAGE"/>

  3. Registration method:

    Intent registrationIntent = new Intent(REQUEST_REGISTRATION_INTENT);
    registrationIntent.setPackage(GSF_PACKAGE);
    registrationIntent.putExtra(EXTRA_APPLICATION_PENDING_INTENT,
            PendingIntent.getBroadcast(getApplicationContext(), 0, new Intent(), 0));
    registrationIntent.putExtra(EXTRA_SENDER, "app@company.com");
    context.startService(registrationIntent);
    

What exactly do I have to change in order to receive only notifications targeted to the running app (environment)?

Additionally, if the problem is the package name, I don't understand exactly why. Let's say I login with debug version. Register with package name x. Now I register with production, also with package name x. Will I receive the notifications from debug, because it was registered previously with the same package name? Does this mean that if I never used/registered with debug version, I will never receive notifications from debug environment using production app?


Solution

  • Currently, I have just renamed the package for DEBUG environment.So it's like I'm having other app, it get's pretty messy but ... I don't know if there is another solution , but I'll be glad to find out :)

    EDIT: maybe it can be resolved from the third server party. I mean, at registration you can sent to your server a variable with value debug/staging/prod and it will put your device id in one of the 3 databases(one with app registered for debug , one for staging, one for prod) Please let me know what do you think about this!