Skip to content

Commit 9f94208

Browse files
labtopiaAndroid (Google) Code Review
authored andcommitted
Merge changes I9bd42a8a,I613d0b12 into jb-dev
* changes: cherrypick from master docs: GCM changes Change-Id: Id5454e70455bae14ab4605021a6c1bcab0292ae9 Doc update: Misc minor GCM updates.
2 parents 9c31127 + dd983ad commit 9f94208

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

docs/html/guide/google/gcm/gcm.jd

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ page.title=GCM Architectural Overview
5656
</div>
5757
</div>
5858

59-
<p>Google Cloud Messaging for Android (GCM) is a service that helps
59+
<p>Google Cloud Messaging for Android (GCM) is a free service that helps
6060
developers send data from servers to their Android applications on Android devices. This could be a lightweight message telling the Android application that there is new data to be fetched from the server (for instance, a movie uploaded by a friend), or it could be a message containing up to 4kb of payload data (so apps like instant messaging can consume the message directly). The GCM service handles all aspects of queueing of
6161
messages and delivery to the target Android application running on the target
6262
device.</p>
@@ -545,7 +545,8 @@ private void handleRegistration(Intent intent) {
545545
<p>The <code>com.google.android.c2dm.intent.RECEIVE</code> intent is used by GCM to
546546
deliver the messages sent by the 3rd-party server to the application running in the device.
547547
If the server included key-pair values in the <code>data</code> parameter, they are available as
548-
extras in this intent, with the keys being the extra names.
548+
extras in this intent, with the keys being the extra names. GCM also includes an extra called
549+
<code>from</code> which contains the sender ID as an string.
549550

550551
<p>Here is an example, again using the <code>MyIntentReceiver</code> class:</p>
551552

@@ -651,8 +652,9 @@ message sent by the application server. See <a href="adv.html#collapsible">Advan
651652
<tr>
652653
<td><code>data</code></td>
653654
<td>A JSON object whose fields represents the key-value pairs of the message's payload data. If present, the payload data it will be
654-
included in the Intent as application data, with the key being the extra's name. For instance, <code>"data":{"score":"3x1"}</code> would result in an intent extra named <code>score</code> whose value is the string <code>3x1</code>
655-
There is no limit on the number of key/value pairs, though there is a limit on the total size of the message. Optional.</td>
655+
included in the Intent as application data, with the key being the extra's name. For instance, <code>"data":{"score":"3x1"}</code> would result in an intent extra named <code>score</code> whose value is the string <code>3x1</code>.
656+
There is no limit on the number of key/value pairs, though there is a limit on the total size of the message (4kb). Note that the values <em>must be enclosed by strings</em>. If you want to include objects or other non-string data types (such as integers or booleans), you have to do the conversion to string yourself. Also note that the key cannot be a reserved word (<code>from</code> or any word starting with <code>google.</code>). Optional.</td>
657+
656658
</tr>
657659
<tr>
658660
<td><code>delay_while_idle</code></td>
@@ -683,7 +685,7 @@ sent. Optional. The default value is <code>false</code>, and must be a JSON bool
683685
</tr>
684686
<tr>
685687
<td><code>data.&lt;key&gt;</code></td>
686-
<td>Payload data, expressed as parameters prefixed with <code>data.</code> and suffixed as the key. For instance, a parameter of <code>data.score=3x1</code> would result in an intent extra named <code>score</code> whose value is the string <code>3x1</code>. There is no limit on the number of key/value parameters, though there is a limit on the total size of the message. Optional.</td>
688+
<td>Payload data, expressed as parameters prefixed with <code>data.</code> and suffixed as the key. For instance, a parameter of <code>data.score=3x1</code> would result in an intent extra named <code>score</code> whose value is the string <code>3x1</code>. There is no limit on the number of key/value parameters, though there is a limit on the total size of the message. Note that the key cannot be a reserved word (<code>from</code> or any word starting with <code>google.</code>). Optional.</td>
687689
</tr>
688690
<tr>
689691
<td><code>delay_while_idle</code></td>
@@ -695,7 +697,7 @@ sent. Optional. The default value is <code>false</code>, and must be a JSON bool
695697
</tr>
696698
</table>
697699

698-
700+
<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 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>
699701

700702
<h4 id="example-requests">Example requests</h4>
701703
<p>Here is the smallest possible request (a message without any parameters and just one recipient) using JSON:</p>
@@ -879,8 +881,22 @@ messages.
879881
<li>Request originated from a server not whitelisted in the Server Key IPs.</li>
880882

881883
</ul>
882-
Check that the token you're sending inside the <code>Authorization</code> header is the correct API key associated with your project.<br/>
884+
Check that the token you're sending inside the <code>Authorization</code> header is the correct API key associated with your project. You can check the validity of your API key by running the following command:<br/>
885+
886+
887+
<pre># api_key=YOUR_API_KEY
888+
889+
# curl --header "Authorization: key=$api_key" --header Content-Type:"application/json" https://android.googleapis.com/gcm/send -d "{\"registration_ids\":[\"ABC\"]}"</pre>
883890

891+
892+
893+
If you receive a 401 HTTP status code, your API key is not valid. Otherwise you should see something like this:<br/>
894+
895+
<pre>
896+
{"multicast_id":6782339717028231855,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}
897+
</pre>
898+
If you want to confirm the validity of a registration ID, you can do so by replacing "ABC" with the registration ID.
899+
<br/>
884900
Happens when the HTTP status code is 401.
885901

886902
<dt id="timeout"><strong>Timeout</strong></dt>
@@ -974,14 +990,16 @@ registration_id=32
974990

975991
<p>To view statistics and any error messages for your GCM applications:</p>
976992
<ol>
977-
<li> Go to <code><a href="http://play.google.com/apps/publish">play.google.com/apps/publish</a></code>.</li>
993+
<li> Go to the <code><a href="http://play.google.com/apps/publish">Android Developer Console</a></code>.</li>
978994
<li>Login with your developer account.
979995
<p>You will see a page that has a list of all of your apps.</p></li>
980996
<li> Click on the &quot;statistics&quot; link next to the app for which you want to view GCM stats.
981997
<p>Now you are on the statistics page.</p> </li>
982998
<li>Go to the drop-down menu and select the GCM metric you want to view.
983999
</li>
9841000
</ol>
1001+
<p class="note"><strong>Note:</strong> Stats on the Google API Console are not enabled for GCM. You must use the <a href="http://play.google.com/apps/publish">Android Developer Console</a>.</p>
1002+
9851003
<h2 id="example">Examples</h2>
9861004
<p>See the <a href="demo.html">GCM Demo Application</a> document.</p>
9871005

docs/html/guide/google/gcm/index.jd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ page.title=Google Cloud Messaging for Android
55
<p><img src="{@docRoot}images/gcm/gcm-logo.png" /></p>
66
<p>Google Cloud Messaging for Android (GCM) is a service that helps developers send data from servers to their Android applications on Android devices. This could be a lightweight message telling the Android application that there is new data to be fetched from the server (for instance, a movie uploaded by a friend), or it could be a message containing up to 4kb of payload data (so apps like instant messaging can consume the message directly). The GCM service handles all aspects of queueing of messages and delivery to the target Android application running on the target device.</p>
77

8+
<p>GCM is completely free no matter how big your messaging needs are, and there are no quotas.</p>
9+
810
<p>To learn more about GCM, you can join the <a href="https://groups.google.com/forum/?fromgroups#!forum/android-gcm">android-gcm group</a> and read the following documents:</p>
911

1012
<dl>

0 commit comments

Comments
 (0)