0

Take a look at the sample manifest here - https://developer.android.com/google/gcm/client.html

My question is howcome the receiver receives broadcast with the permission android:permission="com.google.android.c2dm.permission.SEND" when no uses-permission or permission tag is used with the same string ?

-- solved --

Note: don't forget to read the comments in the selected answer.

user1437328
  • 15,546
  • 9
  • 34
  • 44

1 Answers1

1

Your app is the one defending itself with the permission.

The sender -- in this case, something in Google Play Services that handles the GCM connection -- is the one that needs to hold the permission, via <uses-permission> or the equivalent.

The <permission> itself is being defined by Google Play Services, presumably, given the permission name.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • So what you're saying is Google play services (sender) app contains the `uses-permission` as well as the `permission` tags defining the permission string. All I have to do is use it in the receiver tag and then I'll be able to receive broadcasts from the sender app. So in order to test this, I created 2 apps A and B. A has a broadcast receiver. Here's how the manifest (and code) for both looks like - http://pastie.org/private/hqoapkl7wiuksjmpdo0dga I mentioned the problem in there, which is, A doesn't receives broadcast from B. What am I doing wrong or failing to understand ? – user1437328 Dec 02 '14 at 13:52
  • @user1437328: There is nothing in that code that has anything to do with GCM. If you want this to work, get rid of the second parameter to `sendBroadcast()` and ensure that B is installed before A. – CommonsWare Dec 02 '14 at 23:31
  • I agree that has nothing to do with GCM, but for the sake of testing similar situation I wrote my own piece to understand. I'll do what you said and see if the broadcast works or not. – user1437328 Dec 03 '14 at 04:25
  • ok, this seems to work (although I'll test more). Seems like the key was to remove the second argument from `sendBroadcast()`. This is a little strange as the [Security](http://developer.android.com/reference/android/content/BroadcastReceiver.html#Security) guide mentions the usage of second argument. So does this [thread](http://stackoverflow.com/a/15316487) which is a slightly different example (or maybe not as the only difference is I put `uses-permission` tag in the sender app manifest (B) rather than the receiver app manifest (A). Any idea why the second argument had to be removed ? – user1437328 Dec 03 '14 at 04:33
  • @user1437328: "Seems like the key was to remove the second argument from sendBroadcast()" -- those are for different roles. In the GCM scenario, the *receiver* is defending itself against rogue *senders*. In the two-parameter `sendBroadcast()` scenario, the *sender* is defending itself against rogue *receivers*. – CommonsWare Dec 03 '14 at 11:52