4

I have an app (com.example.myapp) installed that received C2DM Intents. I would like to piggyback onto this to perform my own processing in response to these Intents in a separate app (com.example.myapp2). According to the this answer, the C2DM client system looks for:

broadcast receivers for Intent: com.google.android.c2dm.intent.REGISTRATION

That have the permission: .permission.C2D_MESSAGE

In the original app, the following permission is defined and used, as specified in the C2DM Documentation

  <!-- Only this application can receive the messages and registration result --> 
   <permission android:name="com.example.myapp.permission.C2D_MESSAGE" android:protectionLevel="signature" />
   <uses-permission android:name="com.example.myapp.permission.C2D_MESSAGE" />

This is com.example.myapp2's manifest, in which I use that permission also:

<manifest package="com.example.myapp2" ...>

   <!-- Only this application can receive the messages and registration result --> 
   <uses-permission android:name="com.example.myapp.permission.C2D_MESSAGE" />

   <!-- This app has permission to register and receive message -->
   <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

   <!-- Send the registration id to the server -->
   <uses-permission android:name="android.permission.INTERNET" />

   <application...>
      <!-- Only C2DM servers can send messages for the app. If permission is not set - any other app can generate it --> 
      <receiver android:name=".C2DMReceiver" android:permission="com.google.android.c2dm.permission.SEND">
          <!-- Receive the actual message -->
          <intent-filter>
              <action android:name="com.google.android.c2dm.intent.RECEIVE" />
              <category android:name="com.example.myapp" />
              <category android:name="com.example.myapp2" />
          </intent-filter>
      </receiver>
      ...
   </application>
   ...
</manifest>

My C2DMReceiver is com.example.myapp2.C2DMReceiver. Notice that I'm not listening for com.google.android.c2dm.intent.REGISTRATION Intents since I don't care about registering. I only care about receiving the Intents that com.example.myapp is already receiving. In my IntentFilter for com.google.android.c2dm.intent.RECEIVE Intents, I filter for both com.example.myapp and com.example.myapp2 categorys since C2DM isn't specific about exactly what a C2DM Intent looks like. Any help there would be appreciated.

I've verified that com.example.myapp2 has the com.example.myapp.permission.C2D_MESSAGE permission. If I run with a debug key, I don't have it, but if I run with the release key, I have it. Obviously, I'm running the version on my device with the release key.

When com.example.myapp receives a C2DM Intent com.example.myapp2 doesn't receive it. Any ideas for how to debug or how to get this to work? Is it even possible?

Community
  • 1
  • 1
Heath Borders
  • 30,998
  • 16
  • 147
  • 256

1 Answers1

0

AFAIK This is not possible. When an app registers for C2DM messages it generates a key that is based on the package name of the app and you can only have one of those per device.

If you are using the same signature then I'm assuming you control both apps, if so you'd have to have the app that receives the C2DM message transmit the data to the second app via a service to which they both have access.

Jason Polites
  • 5,571
  • 3
  • 25
  • 24
  • Can you point to some documentation somewhere that talks about the key? I haven't found anything definitive. All the docs talk about posting the broadcast intent, and requiring the C2D_MESSAGE permission. – Heath Borders Mar 25 '13 at 13:59
  • "An ID issued by the GCM servers to the Android application that allows it to receive messages. Once the Android application has the registration ID, it sends it to the 3rd-party application server, which uses it to identify each device that has registered to receive messages for a given Android application. In other words, a registration ID is tied to a particular Android application running on a particular device." http://developer.android.com/google/gcm/gcm.html – Jason Polites Mar 26 '13 at 16:07
  • It's the same. The backend for GCM and C2DM are exactly the same. The only thing that changed is the name, the quota and the client sdk does more for you now that it used to. The rest is exactly the same. – Jason Polites Mar 27 '13 at 17:05
  • "applicationPackage + ".permission.C2D_MESSAGE prevents other applications from registering and receiving the application's messages." from https://developers.google.com/android/c2dm/#manifest implies that you can register for another application's messages if you have the permission, which I have. – Heath Borders Mar 27 '13 at 21:00