You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<h2 id="multi-senders">Receiving Messages from Multiple Senders</h2>
259
259
<p>GCM allows multiple parties to send messages to the same application. For example, suppose your application is an articles aggregator 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.</p>
260
-
<p>To make this possible, all you need to do is have each sender generate its own project ID. 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.</p>
260
+
<p>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.</p>
261
261
<p>This code snippet illustrates this feature. Senders are passed as an intent extra in a comma-separated list:</p>
262
262
<pre class="prettyprint pretty-java">Intent intent = new Intent(GCMConstants.INTENT_TO_GCM_REGISTRATION);
Copy file name to clipboardExpand all lines: docs/html/guide/google/gcm/c2dm.jd
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -55,7 +55,7 @@ page.title=Migration
55
55
<dd>To use the GCM service, you need to obtain a Simple API Key from Google APIs console page. For more information, see <a href="gs.html">Getting Started</a>. Note that GCM <em>only</em> accepts Simple API Key—using ClientLogin or OAuth2 tokens will not work.
56
56
</dd>
57
57
<dt><strong>Sender ID</strong></dt>
58
-
<dd>In C2DM, the Sender ID is an email address. In GCM, the Sender ID is a project ID that you acquire from the API console, as described in <a href="gs.html#create-proj">Getting Started</a>. </dd>
58
+
<dd>In C2DM, the Sender ID is an email address. In GCM, the Sender ID is a project number that you acquire from the API console, as described in <a href="gs.html#create-proj">Getting Started</a>. </dd>
59
59
60
60
<dt><strong>JSON format</strong></dt>
61
61
<dd>GCM HTTP requests support JSON format in addition to plain text. For more information, see the <a href="gcm.html#send-msg">Architectural Overview</a>.</dd>
@@ -82,12 +82,12 @@ page.title=Migration
82
82
<p>C2DM and GCM are not interoperable. For example, you cannot post notifications from GCM to C2DM registration IDs, nor can you use C2DM registration IDs as GCM registration IDs. From your server-side application, you must keep keep track of whether a registration ID is from C2DM or GCM and use the proper endpoint. </p>
83
83
84
84
<p>As you transition from C2DM to GCM, your server needs to be aware of whether a given registration ID
85
-
contains an old C2DM sender or a new GCM project ID. This is the approach we recommend: have the new app version (the one that uses GCM) send a bit along with the registration ID. This bit tells your server that this registration ID is for GCM. If you don't get the extra bit, you mark the registration ID as C2DM. Once no more valid registration IDs are marked as C2DM, you can complete the migration.</p>
85
+
contains an old C2DM sender or a new GCM project number. This is the approach we recommend: have the new app version (the one that uses GCM) send a bit along with the registration ID. This bit tells your server that this registration ID is for GCM. If you don't get the extra bit, you mark the registration ID as C2DM. Once no more valid registration IDs are marked as C2DM, you can complete the migration.</p>
86
86
87
87
<h2 id="migrating">Migrating Your Apps</h2>
88
88
<p>This section describes how to move existing C2DM apps to GCM.</p>
89
89
<h3 id="client">Client changes</h3>
90
-
<p>Migration is simple! The only change required in the application is replacing the email account passed in the sender parameter of the registration intent with the project ID generated when signing up for the new service. For example:</p>
90
+
<p>Migration is simple! The only change required in the application is replacing the email account passed in the sender parameter of the registration intent with the project number generated when signing up for the new service. For example:</p>
91
91
<pre class="prettyprint pretty-java">Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER");
92
92
// sets the app name in the intent
93
93
registrationIntent.putExtra("app", PendingIntent.getBroadcast(this, 0, new Intent(), 0));
Copy file name to clipboardExpand all lines: docs/html/guide/google/gcm/demo.jd
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -62,7 +62,7 @@ page.title=GCM Demo Application
62
62
<p>For the Android application:</p>
63
63
<ul>
64
64
<li>Emulator (or device) running Android 2.2 with Google APIs.</li>
65
-
<li>The Google API project ID of the account registered to use GCM.</li>
65
+
<li>The Google API project number of the account registered to use GCM.</li>
66
66
</ul>
67
67
<h2 id="gcm-setup">Setting Up GCM</h2>
68
68
<p>Before proceeding with the server and client setup, it's necessary to register a Google account with the Google API Console, enable Google Cloud Messaging in GCM, and obtain an API key from the <a href="https://code.google.com/apis/console">Google API Console</a>.</p>
@@ -175,7 +175,7 @@ runserver:
175
175
<pre class="prettyprint pretty-java">
176
176
static final String SERVER_URL = "http://192.168.1.10:8080/gcm-demo";
177
177
static final String SENDER_ID = "4815162342";</pre>
178
-
<p>Note that the <code>SERVER_URL</code> is the URL for the server and the application's context (or just server, if you are using App Engine), and it does not include the forward slash (<code>/</code>). Also note that <code>SENDER_ID</code> is the Google API project ID you obtained in the server setup steps above.</p>
178
+
<p>Note that the <code>SERVER_URL</code> is the URL for the server and the application's context (or just server, if you are using App Engine), and it does not include the forward slash (<code>/</code>). Also note that <code>SENDER_ID</code> is the Google API project number you obtained in the server setup steps above.</p>
179
179
180
180
<li>In a shell window, go to the <code>gcm-demo-client</code> directory.</li>
181
181
<li>Use the SDK's <code>android</code> tool to generate the <code>ant</code> build files:</li>
Copy file name to clipboardExpand all lines: docs/html/guide/google/gcm/gcm.jd
+31-4Lines changed: 31 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -133,7 +133,7 @@ application server and sending them to the device. </td>
133
133
</tr>
134
134
<tr>
135
135
<td><strong>Sender ID</strong></td>
136
-
<td>A project ID you acquire from the API console, as described in <a href="gs.html#create-proj">Getting Started</a>. The sender
136
+
<td>A project number you acquire from the API console, as described in <a href="gs.html#create-proj">Getting Started</a>. The sender
137
137
ID is used in the <a href="#registering">registration process</a> to identify an
138
138
Android application that is permitted to send messages to the device.</td>
139
139
</tr>
@@ -360,7 +360,7 @@ could not run properly. </li>
360
360
</p>
361
361
362
362
<ul>
363
-
<li><code>sender</code> is the project ID of the account authorized to send messages
363
+
<li><code>sender</code> is the project number of the account authorized to send messages
364
364
to the Android application. </li>
365
365
<li><code>app</code> is the Android application's ID, set with a <code>PendingIntent</code> to
366
366
allow the registration service to extract Android application information. </li>
@@ -675,6 +675,16 @@ sent. Optional. The default value is <code>false</code>, and must be a JSON bool
675
675
<td><code>time_to_live</code></td>
676
676
<td>How long (in seconds) the message should be kept on GCM storage if the device is offline. Optional (default time-to-live is 4 weeks, and must be set as a JSON number).</td>
677
677
</tr>
678
+
<tr>
679
+
<td><code>category</code></td>
680
+
<td>A string containing the package name of your application. When set, messages will only be sent to registration IDs that match the category. Optional.
681
+
</td>
682
+
</tr>
683
+
<tr>
684
+
<td><code>dry_run</code></td>
685
+
<td>If included, allows developers to test their request without actually sending a message. Optional. The default value is <code>false</code>, and must be a JSON boolean.
686
+
</td>
687
+
</tr>
678
688
</table>
679
689
680
690
<p>If you are using plain text instead of JSON, the message fields must be set as HTTP parameters sent in the body, and their syntax is slightly different, as described below:
@@ -706,9 +716,19 @@ sent. Optional. The default value is <code>false</code>, and must be a JSON bool
706
716
<td><code>time_to_live</code></td>
707
717
<td>Same as JSON (see previous table). Optional.</td>
708
718
</tr>
719
+
<tr>
720
+
<td><code>category</code></td>
721
+
<td>Same as JSON (see previous table). Optional.
722
+
</td>
723
+
</tr>
724
+
<tr>
725
+
<td><code>dry_run</code></td>
726
+
<td>Same as JSON (see previous table). Optional.
727
+
</td>
728
+
</tr>
709
729
</table>
710
730
711
-
731
+
<p>If you want to test your request (either JSON or plain text) without delivering the message to the devices, you can set an optional HTTP or JSON parameter called <code>dry_run</code> with the value <code>true</code>. The result will be almost identical to running the request without this parameter, except that the message will not be delivered to the devices. Consequently, the response will contain fake IDs for the message and multicast fields (see <a href="#response">Response format</a>).</p>
712
732
713
733
<h4 id="example-requests">Example requests</h4>
714
734
<p>Here is the smallest possible request (a message without any parameters and just one recipient) using JSON:</p>
@@ -889,7 +909,7 @@ Happens when the error code is <code>InvalidDataKey</code>.</dd>
<li> Take note of the value after <code>#project:</code> (4815162342 in this example). This is your project ID, and it will be used later on as the GCM sender ID.</li>
44
+
<li> Take note of the value after <code>#project:</code> (4815162342 in this example). This is your project number, and it will be used later on as the GCM sender ID.</li>
45
45
46
46
</ol>
47
47
<h2 id="gcm-service">Enabling the GCM Service</h2>
0 commit comments