Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 60c8f996 authored by Katie McCormick's avatar Katie McCormick
Browse files

Doc update: GCM doc cleanup, continued.

Change-Id: Ia668bc6b80b5d53c9fa815db888e75d8efbbc772
parent 0f8e402e
Loading
Loading
Loading
Loading
+20 −6
Original line number Original line Diff line number Diff line
@@ -27,6 +27,7 @@ page.title=GCM Advanced Topics
  <ol>
  <ol>
    <li><a href="#s2s">Send-to-sync messages</a></li>
    <li><a href="#s2s">Send-to-sync messages</a></li>
    <li><a href="#payload">Messages with payload</a></li>
    <li><a href="#payload">Messages with payload</a></li>
<li><a href="#which">Which should I use?</a></li>
    </ol>
    </ol>
</li>
</li>
<li><a href="#ttl">Setting an Expiration Date for a Message</a> </li>
<li><a href="#ttl">Setting an Expiration Date for a Message</a> </li>
@@ -185,10 +186,22 @@ registerReceiver(mRetryReceiver, filter);
<p>Note that it might take a while for the registration ID be completely removed from GCM. Thus it is possible that messages sent during step 7 above gets a valid message ID as response, even though the message will not be delivered to the device. Eventually, the registration ID will be removed and the server will get a <code>NotRegistered</code> error, without any further action being required from the 3rd-party server (this scenario happens frequently while an application is being developed and tested).</p>
<p>Note that it might take a while for the registration ID be completely removed from GCM. Thus it is possible that messages sent during step 7 above gets a valid message ID as response, even though the message will not be delivered to the device. Eventually, the registration ID will be removed and the server will get a <code>NotRegistered</code> error, without any further action being required from the 3rd-party server (this scenario happens frequently while an application is being developed and tested).</p>


<h2 id="collapsible">Send-to-Sync  vs. Messages with Payload</h2>
<h2 id="collapsible">Send-to-Sync  vs. Messages with Payload</h2>
<p>Every message sent in GCM, regardless of its other characteristics, is either a &quot;send-to-sync&quot; (collapsible) message or a &quot;message with payload&quot; (non-collapsible message).</p>

<p>Every message sent in GCM has the following characteristics:</p>
<ul>
  <li>It has a payload limit of 4096 bytes.</li>
  <li>By default, it is stored by GCM for 4 weeks.</li>
</ul>

<p>But despite these similarities, messages can behave very differently depending on their particular settings. One major distinction between messages is whether they are collapsed (where each new message replaces the preceding message) or not collapsed (where each individual message is delivered). Every message sent in GCM is either a &quot;send-to-sync&quot; (collapsible) message or a &quot;message with payload&quot; (non-collapsible message). These concepts are described in more detail in the following sections.</p>

<h3 id="s2s"><strong>Send-to-sync messages</strong></h3>
<h3 id="s2s"><strong>Send-to-sync messages</strong></h3>
<p>A send-to-sync (collapsible) message is typically a &quot;tickle&quot; that tells a mobile application to sync data from the server. For example, suppose you have an email application. When a user receives new email on the server, the server pings the mobile application with a &quot;New mail&quot; message. This tells the application to sync to the server to pick up the new email. The server might send this message multiple times as new mail continues to accumulate, before the application has had a chance to sync. But if the user has received 25 new emails, there's no need to preserve every &quot;New mail&quot; message. One  is sufficient. This is a case where you would use the GCM <code>collapse_key</code> parameter. A <em>collapse key</em> is an arbitrary string that is used to collapse a group of like messages when the device is offline, so that only the last message gets sent to the client. For example, &quot;New mail,&quot; &quot;Updates available,&quot; and so on</p>

<p>GCM allows a maximum of 4 different collapse keys to be used by the GCM server at any given time. In other words, the GCM server can simultaneously store 4 different send-to-sync messages, each with a different collapse key.</p>
<p>A send-to-sync (collapsible) message is often a &quot;tickle&quot; that tells a mobile application to sync data from the server. For example, suppose you have an email application. When a user receives new email on the server, the server pings the mobile application with a &quot;New mail&quot; message. This tells the application to sync to the server to pick up the new email. The server might send this message multiple times as new mail continues to accumulate, before the application has had a chance to sync. But if the user has received 25 new emails, there's no need to preserve every &quot;New mail&quot; message. One is sufficient. Another example would be a sports application that updates users with the latest score. Only the most recent message is relevant, so it makes sense to have each new message replace the preceding message. </p>

<p>The email and sports applications are cases where you would probably use the GCM <code>collapse_key</code> parameter. A <em>collapse key</em> is an arbitrary string that is used to collapse a group of like messages when the device is offline, so that only the most recent message gets sent to the client. For example, &quot;New mail,&quot; &quot;Updates available,&quot; and so on</p>
<p>GCM allows a maximum of 4 different collapse keys to be used by the GCM server at any given time. In other words, the GCM server can simultaneously store 4 different send-to-sync messages, each with a different collapse key. If you exceed this number GCM will only keep 4 collapse keys, with no guarantees about which ones they will be.</p>

<h3 id="payload">Messages with payload</h3>
<h3 id="payload">Messages with payload</h3>
<p>Unlike a send-to-sync message, every &quot;message with payload&quot; (non-collapsible message) is delivered. The payload the message contains can be up to 4K. For example, here is a JSON-formatted message in an IM application in which spectators are discussing a sporting event:</p>
<p>Unlike a send-to-sync message, every &quot;message with payload&quot; (non-collapsible message) is delivered. The payload the message contains can be up to 4K. For example, here is a JSON-formatted message in an IM application in which spectators are discussing a sporting event:</p>


@@ -208,9 +221,10 @@ registerReceiver(mRetryReceiver, filter);
  <li><code>total_deleted</code>&mdash;The value  is a string with the number of deleted messages.</li>
  <li><code>total_deleted</code>&mdash;The value  is a string with the number of deleted messages.</li>
</ul>
</ul>
<p>The application should respond by syncing with the server to recover the discarded messages. </p>
<p>The application should respond by syncing with the server to recover the discarded messages. </p>
  <p class="note"><strong>Note:</strong> If your application does not need to use non-collapsible messages, collapsible messages are a better choice from a performance standpoint, because they put less of a burden on the device battery.


</p>
<h3 id="which">Which should I use?</h3>
  <p>If your application does not need to use non-collapsible messages, collapsible messages are a better choice from a performance standpoint, because they put less of a burden on the device battery.</p>

<h2 dir="ltr" id="ttl">Setting an Expiration Date for a Message</h2>
<h2 dir="ltr" id="ttl">Setting an Expiration Date for a Message</h2>
<p>The Time to Live (TTL) feature lets  the sender  specify the maximum lifespan of a message using the <code>time_to_live</code> parameter in the send request. The value of this parameter must be a duration from 0 to 2,419,200 seconds, and it corresponds to the maximum period of time for which GCM will store and try to deliver the message. Requests that don't contain this field default to the maximum period of 4 weeks.</p>
<p>The Time to Live (TTL) feature lets  the sender  specify the maximum lifespan of a message using the <code>time_to_live</code> parameter in the send request. The value of this parameter must be a duration from 0 to 2,419,200 seconds, and it corresponds to the maximum period of time for which GCM will store and try to deliver the message. Requests that don't contain this field default to the maximum period of 4 weeks.</p>
<p>Here are some possible uses for this feature:</p>
<p>Here are some possible uses for this feature:</p>
+3 −3
Original line number Original line Diff line number Diff line
@@ -2,14 +2,14 @@
<!--NewPage-->
<!--NewPage-->
<HTML>
<HTML>
<HEAD>
<HEAD>
<!-- Generated by javadoc (build 1.6.0_20) on Thu Jun 21 12:06:25 PDT 2012 -->
<!-- Generated by javadoc (build 1.6.0_26) on Mon Jul 16 14:13:37 PDT 2012 -->
<TITLE>
<TITLE>
All Classes
All Classes
</TITLE>
</TITLE>


<META NAME="date" CONTENT="2012-06-21">
<META NAME="date" CONTENT="2012-07-16">


<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
<LINK REL ="stylesheet" TYPE="text/css" HREF="default.css" TITLE="Style">




</HEAD>
</HEAD>
+3 −3
Original line number Original line Diff line number Diff line
@@ -2,14 +2,14 @@
<!--NewPage-->
<!--NewPage-->
<HTML>
<HTML>
<HEAD>
<HEAD>
<!-- Generated by javadoc (build 1.6.0_20) on Thu Jun 21 12:06:25 PDT 2012 -->
<!-- Generated by javadoc (build 1.6.0_26) on Mon Jul 16 14:13:37 PDT 2012 -->
<TITLE>
<TITLE>
All Classes
All Classes
</TITLE>
</TITLE>


<META NAME="date" CONTENT="2012-06-21">
<META NAME="date" CONTENT="2012-07-16">


<LINK REL ="stylesheet" TYPE="text/css" HREF="stylesheet.css" TITLE="Style">
<LINK REL ="stylesheet" TYPE="text/css" HREF="default.css" TITLE="Style">




</HEAD>
</HEAD>
+61 −10
Original line number Original line Diff line number Diff line
@@ -2,14 +2,14 @@
<!--NewPage-->
<!--NewPage-->
<HTML>
<HTML>
<HEAD>
<HEAD>
<!-- Generated by javadoc (build 1.6.0_20) on Thu Jun 21 12:06:25 PDT 2012 -->
<!-- Generated by javadoc (build 1.6.0_26) on Mon Jul 16 14:13:36 PDT 2012 -->
<TITLE>
<TITLE>
GCMBaseIntentService
GCMBaseIntentService
</TITLE>
</TITLE>


<META NAME="date" CONTENT="2012-06-21">
<META NAME="date" CONTENT="2012-07-16">


<LINK REL ="stylesheet" TYPE="text/css" HREF="../../../../stylesheet.css" TITLE="Style">
<LINK REL ="stylesheet" TYPE="text/css" HREF="../../../../default.css" TITLE="Style">


<SCRIPT type="text/javascript">
<SCRIPT type="text/javascript">
function windowTitle()
function windowTitle()
@@ -107,6 +107,8 @@ Skeleton for application-specific <CODE>IntentService</CODE>s responsible for
 hence should run in a limited amount of time. If they execute long
 hence should run in a limited amount of time. If they execute long
 operations, they should spawn new threads, otherwise the worker thread will
 operations, they should spawn new threads, otherwise the worker thread will
 be blocked.
 be blocked.
 <p>
 Subclasses must provide a public no-arg constructor.
<P>
<P>


<P>
<P>
@@ -142,11 +144,19 @@ Skeleton for application-specific <CODE>IntentService</CODE>s responsible for
<TR BGCOLOR="white" CLASS="TableRowColor">
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>protected </CODE></FONT></TD>
<CODE>protected </CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../com/google/android/gcm/GCMBaseIntentService.html#GCMBaseIntentService(java.lang.String)">GCMBaseIntentService</A></B>(java.lang.String&nbsp;senderId)</CODE>
<TD><CODE><B><A HREF="../../../../com/google/android/gcm/GCMBaseIntentService.html#GCMBaseIntentService()">GCMBaseIntentService</A></B>()</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Constructor that does not set a sender id, useful when the sender id
 is context-specific.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>protected </CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../com/google/android/gcm/GCMBaseIntentService.html#GCMBaseIntentService(java.lang.String...)">GCMBaseIntentService</A></B>(java.lang.String...&nbsp;senderIds)</CODE>


<BR>
<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Subclasses must create a public no-arg constructor and pass the
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Constructor used when the sender id(s) is fixed.</TD>
 sender id to be used for registration.</TD>
</TR>
</TR>
</TABLE>
</TABLE>
&nbsp;
&nbsp;
@@ -160,6 +170,14 @@ Skeleton for application-specific <CODE>IntentService</CODE>s responsible for
</TR>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>protected &nbsp;java.lang.String[]</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../com/google/android/gcm/GCMBaseIntentService.html#getSenderIds(Context)">getSenderIds</A></B>(Context&nbsp;context)</CODE>

<BR>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Gets the sender ids.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>protected &nbsp;void</CODE></FONT></TD>
<CODE>protected &nbsp;void</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../../com/google/android/gcm/GCMBaseIntentService.html#onDeletedMessages(Context, int)">onDeletedMessages</A></B>(Context&nbsp;context,
<TD><CODE><B><A HREF="../../../../com/google/android/gcm/GCMBaseIntentService.html#onDeletedMessages(Context, int)">onDeletedMessages</A></B>(Context&nbsp;context,
                  int&nbsp;total)</CODE>
                  int&nbsp;total)</CODE>
@@ -263,13 +281,28 @@ public static final java.lang.String <B>TAG</B></PRE>
</TR>
</TR>
</TABLE>
</TABLE>


<A NAME="GCMBaseIntentService(java.lang.String)"><!-- --></A><H3>
<A NAME="GCMBaseIntentService()"><!-- --></A><H3>
GCMBaseIntentService</H3>
<PRE>
protected <B>GCMBaseIntentService</B>()</PRE>
<DL>
<DD>Constructor that does not set a sender id, useful when the sender id
 is context-specific.
 <p>
 When using this constructor, the subclass <strong>must</strong>
 override <A HREF="../../../../com/google/android/gcm/GCMBaseIntentService.html#getSenderIds(Context)"><CODE>getSenderIds(Context)</CODE></A>, otherwise methods such as
 <A HREF="../../../../com/google/android/gcm/GCMBaseIntentService.html#onHandleIntent(Intent)"><CODE>onHandleIntent(Intent)</CODE></A> will throw an
 <CODE>IllegalStateException</CODE> on runtime.
<P>
</DL>
<HR>

<A NAME="GCMBaseIntentService(java.lang.String...)"><!-- --></A><H3>
GCMBaseIntentService</H3>
GCMBaseIntentService</H3>
<PRE>
<PRE>
protected <B>GCMBaseIntentService</B>(java.lang.String&nbsp;senderId)</PRE>
protected <B>GCMBaseIntentService</B>(java.lang.String...&nbsp;senderIds)</PRE>
<DL>
<DL>
<DD>Subclasses must create a public no-arg constructor and pass the
<DD>Constructor used when the sender id(s) is fixed.
 sender id to be used for registration.
<P>
<P>
</DL>
</DL>


@@ -283,6 +316,24 @@ protected <B>GCMBaseIntentService</B>(java.lang.String&nbsp;senderId)</PRE>
</TR>
</TR>
</TABLE>
</TABLE>


<A NAME="getSenderIds(Context)"><!-- --></A><H3>
getSenderIds</H3>
<PRE>
protected java.lang.String[] <B>getSenderIds</B>(Context&nbsp;context)</PRE>
<DL>
<DD>Gets the sender ids.

 <p>By default, it returns the sender ids passed in the constructor, but
 it could be overridden to provide a dynamic sender id.
<P>
<DD><DL>

<DT><B>Throws:</B>
<DD><CODE>java.lang.IllegalStateException</CODE> - if sender id was not set on constructor.</DL>
</DD>
</DL>
<HR>

<A NAME="onMessage(Context, Intent)"><!-- --></A><H3>
<A NAME="onMessage(Context, Intent)"><!-- --></A><H3>
onMessage</H3>
onMessage</H3>
<PRE>
<PRE>
+3 −3
Original line number Original line Diff line number Diff line
@@ -2,14 +2,14 @@
<!--NewPage-->
<!--NewPage-->
<HTML>
<HTML>
<HEAD>
<HEAD>
<!-- Generated by javadoc (build 1.6.0_20) on Thu Jun 21 12:06:25 PDT 2012 -->
<!-- Generated by javadoc (build 1.6.0_26) on Mon Jul 16 14:13:36 PDT 2012 -->
<TITLE>
<TITLE>
GCMBroadcastReceiver
GCMBroadcastReceiver
</TITLE>
</TITLE>


<META NAME="date" CONTENT="2012-06-21">
<META NAME="date" CONTENT="2012-07-16">


<LINK REL ="stylesheet" TYPE="text/css" HREF="../../../../stylesheet.css" TITLE="Style">
<LINK REL ="stylesheet" TYPE="text/css" HREF="../../../../default.css" TITLE="Style">


<SCRIPT type="text/javascript">
<SCRIPT type="text/javascript">
function windowTitle()
function windowTitle()
Loading