1<!DOCTYPE html>
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99<html>
100<head>
101
102
103<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
104<meta name="viewport" content="width=device-width" />
105
106<link rel="shortcut icon" type="image/x-icon" href="/favicon.ico" />
107<title>GoogleCloudMessaging | Android Developers</title>
108
109<!-- STYLESHEETS -->
110<link rel="stylesheet"
111href="//fonts.googleapis.com/css?family=Roboto+Condensed">
112<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Roboto:light,regular,medium,thin,italic,mediumitalic,bold"
113  title="roboto">
114<link href="/assets/css/default.css?v=4" rel="stylesheet" type="text/css">
115
116
117
118<!-- JAVASCRIPT -->
119<script src="//www.google.com/jsapi" type="text/javascript"></script>
120<script src="/assets/js/android_3p-bundle.js" type="text/javascript"></script>
121<script type="text/javascript">
122  var toRoot = "/";
123  var metaTags = [];
124  var devsite = false;
125</script>
126<script src="/assets/js/docs.js?v=3" type="text/javascript"></script>
127
128
129
130<script>
131  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
132  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
133  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
134  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');
135
136  ga('create', 'UA-5831155-1', 'android.com');
137  ga('create', 'UA-49880327-2', 'android.com', {'name': 'universal'});  // New tracker);
138  ga('send', 'pageview');
139  ga('universal.send', 'pageview'); // Send page view for new tracker.
140</script>
141
142</head>
143
144<body class="gc-documentation google
145  develop reference" itemscope itemtype="http://schema.org/Article">
146  <div id="doc-api-level" class="" style="display:none"></div>
147  <a name="top"></a>
148
149
150<a name="top"></a>
151
152<!-- dialog to prompt lang pref change when loaded from hardcoded URL
153<div id="langMessage" style="display:none">
154  <div>
155    <div class="lang en">
156      <p>You requested a page in English, would you like to proceed with this language setting?</p>
157    </div>
158    <div class="lang es">
159      <p>You requested a page in Spanish (Español), would you like to proceed with this language setting?</p>
160    </div>
161    <div class="lang ja">
162      <p>You requested a page in Japanese (日本語), would you like to proceed with this language setting?</p>
163    </div>
164    <div class="lang ko">
165      <p>You requested a page in Korean (한국어), would you like to proceed with this language setting?</p>
166    </div>
167    <div class="lang ru">
168      <p>You requested a page in Russian (Русский), would you like to proceed with this language setting?</p>
169    </div>
170    <div class="lang zh-cn">
171      <p>You requested a page in Simplified Chinese (简体中文), would you like to proceed with this language setting?</p>
172    </div>
173    <div class="lang zh-tw">
174      <p>You requested a page in Traditional Chinese (繁體中文), would you like to proceed with this language setting?</p>
175    </div>
176    <a href="#" class="button yes" onclick="return false;">
177      <span class="lang en">Yes</span>
178      <span class="lang es">Sí</span>
179      <span class="lang ja">Yes</span>
180      <span class="lang ko">Yes</span>
181      <span class="lang ru">Yes</span>
182      <span class="lang zh-cn">是的</span>
183      <span class="lang zh-tw">没有</span>
184    </a>
185    <a href="#" class="button" onclick="$('#langMessage').hide();return false;">
186      <span class="lang en">No</span>
187      <span class="lang es">No</span>
188      <span class="lang ja">No</span>
189      <span class="lang ko">No</span>
190      <span class="lang ru">No</span>
191      <span class="lang zh-cn">没有</span>
192      <span class="lang zh-tw">没有</span>
193    </a>
194  </div>
195</div> -->
196
197
198  <!-- Header -->
199  <div id="header-wrapper">
200    <div id="header">
201
202
203
204
205      <div class="wrap" id="header-wrap">
206        <div class="col-3 logo">
207          <a href="/index.html">
208            <img src="/assets/images/dac_logo.png"
209                srcset="/assets/images/dac_logo@2x.png 2x"
210                width="123" height="25" alt="Android Developers" />
211          </a>
212          <div class="btn-quicknav" id="btn-quicknav">
213            <a href="#" class="arrow-inactive">Quicknav</a>
214            <a href="#" class="arrow-active">Quicknav</a>
215          </div>
216        </div>
217        <ul class="nav-x col-9">
218            <li class="design">
219              <a href="/design/index.html"
220              zh-tw-lang="設計"
221              zh-cn-lang="设计"
222              ru-lang="Проектирование"
223              ko-lang="디자인"
224              ja-lang="設計"
225              es-lang="Diseñar"
226              >Design</a></li>
227            <li class="develop"><a href="/develop/index.html"
228              zh-tw-lang="開發"
229              zh-cn-lang="开发"
230              ru-lang="Разработка"
231              ko-lang="개발"
232              ja-lang="開発"
233              es-lang="Desarrollar"
234              >Develop</a></li>
235            <li class="distribute last"><a href="/distribute/index.html"
236              zh-tw-lang="發佈"
237              zh-cn-lang="分发"
238              ru-lang="Распространение"
239              ko-lang="배포"
240              ja-lang="配布"
241              es-lang="Distribuir"
242              >Distribute</a></li>
243        </ul>
244
245
246
247
248<div class="menu-container">
249  <div class="moremenu">
250    <div id="more-btn"></div>
251  </div>
252  <div class="morehover" id="moremenu">
253    <div class="top"></div>
254    <div class="mid">
255      <div class="header">Links</div>
256      <ul>
257        <li><a href="https://play.google.com/apps/publish/" target="_googleplay">Google Play Developer Console</a></li>
258        <li><a href="http://android-developers.blogspot.com/">Android Developers Blog</a></li>
259        <li><a href="/about/index.html">About Android</a></li>
260      </ul>
261      <div class="header">Android Sites</div>
262      <ul>
263        <li><a href="http://www.android.com">Android.com</a></li>
264        <li class="active"><a>Android Developers</a></li>
265        <li><a href="http://source.android.com">Android Open Source Project</a></li>
266      </ul>
267
268
269
270        <div class="header">Language</div>
271          <div id="language" class="locales">
272            <select name="language" onChange="changeLangPref(this.value, true)">
273                <option value="en">English</option>
274                <option value="es">Español</option>
275                <option value="ja">日本語</option>
276                <option value="ko">한국어</option>
277                <option value="ru">Русский</option>
278                <option value="zh-cn">中文(简体)</option>
279                <option value="zh-tw">中文(繁體)</option>
280            </select>
281          </div>
282        <script type="text/javascript">
283          <!--
284          loadLangPref();
285            //-->
286        </script>
287
288
289      <br class="clearfix" />
290    </div><!-- end 'mid' -->
291    <div class="bottom"></div>
292  </div><!-- end 'moremenu' -->
293
294  <div class="search" id="search-container">
295    <div class="search-inner">
296      <div id="search-btn"></div>
297      <div class="left"></div>
298      <form onsubmit="return submit_search()">
299        <input id="search_autocomplete" type="text" value="" autocomplete="off" name="q"
300          onfocus="search_focus_changed(this, true)" onblur="search_focus_changed(this, false)"
301          onkeydown="return search_changed(event, true, '/')"
302          onkeyup="return search_changed(event, false, '/')" />
303      </form>
304      <div class="right"></div>
305      <a class="close hide">close</a>
306      <div class="left"></div>
307      <div class="right"></div>
308    </div><!-- end search-inner -->
309  </div><!-- end search-container -->
310
311  <div class="search_filtered_wrapper reference">
312    <div class="suggest-card reference no-display">
313      <ul class="search_filtered">
314      </ul>
315    </div>
316  </div>
317
318  <div class="search_filtered_wrapper docs">
319    <div class="suggest-card dummy no-display">&nbsp;</div>
320    <div class="suggest-card develop no-display">
321      <ul class="search_filtered">
322      </ul>
323      <div class="child-card guides no-display">
324      </div>
325      <div class="child-card training no-display">
326      </div>
327      <div class="child-card samples no-display">
328      </div>
329    </div>
330    <div class="suggest-card design no-display">
331      <ul class="search_filtered">
332      </ul>
333    </div>
334    <div class="suggest-card distribute no-display">
335      <ul class="search_filtered">
336      </ul>
337    </div>
338  </div>
339</div><!-- end menu-container (search and menu widget) -->
340
341
342
343        <!-- Expanded quicknav -->
344        <div id="quicknav" class="col-13">
345          <ul>
346            <li class="about">
347              <ul>
348                <li><a href="/about/index.html">About</a></li>
349                <li><a href="/wear/index.html">Wear</a></li>
350                <li><a href="/tv/index.html">TV</a></li>
351                <li><a href="/auto/index.html">Auto</a></li>
352              </ul>
353            </li>
354            <li class="design">
355              <ul>
356                <li><a href="/design/index.html">Get Started</a></li>
357                <li><a href="/design/devices.html">Devices</a></li>
358                <li><a href="/design/style/index.html">Style</a></li>
359                <li><a href="/design/patterns/index.html">Patterns</a></li>
360                <li><a href="/design/building-blocks/index.html">Building Blocks</a></li>
361                <li><a href="/design/downloads/index.html">Downloads</a></li>
362                <li><a href="/design/videos/index.html">Videos</a></li>
363              </ul>
364            </li>
365            <li class="develop">
366              <ul>
367                <li><a href="/training/index.html"
368                  zh-tw-lang="訓練課程"
369                  zh-cn-lang="培训"
370                  ru-lang="Курсы"
371                  ko-lang="교육"
372                  ja-lang="トレーニング"
373                  es-lang="Capacitación"
374                  >Training</a></li>
375                <li><a href="/guide/index.html"
376                  zh-tw-lang="API 指南"
377                  zh-cn-lang="API 指南"
378                  ru-lang="Руководства по API"
379                  ko-lang="API 가이드"
380                  ja-lang="API ガイド"
381                  es-lang="Guías de la API"
382                  >API Guides</a></li>
383                <li><a href="/reference/packages.html"
384                  zh-tw-lang="參考資源"
385                  zh-cn-lang="参考"
386                  ru-lang="Справочник"
387                  ko-lang="참조문서"
388                  ja-lang="リファレンス"
389                  es-lang="Referencia"
390                  >Reference</a></li>
391                <li><a href="/sdk/index.html"
392                  zh-tw-lang="相關工具"
393                  zh-cn-lang="工具"
394                  ru-lang="Инструменты"
395                  ko-lang="도구"
396                  ja-lang="ツール"
397                  es-lang="Herramientas"
398                  >Tools</a>
399                </li>
400                <li><a href="/google/index.html">Google Services</a>
401                </li>
402
403                  <li><a href="/samples/index.html">Samples</a>
404                  </li>
405
406              </ul>
407            </li>
408            <li class="distribute last">
409              <ul>
410                <li><a href="/distribute/googleplay/index.html">Google Play</a></li>
411                <li><a href="/distribute/essentials/index.html">Essentials</a></li>
412                <li><a href="/distribute/users/index.html">Get Users</a></li>
413                <li><a href="/distribute/engage/index.html">Engage &amp; Retain</a></li>
414                <li><a href="/distribute/monetize/index.html">Monetize</a></li>
415                <li><a href="/distribute/tools/index.html">Tools &amp; Reference</a></li>
416                <li><a href="/distribute/stories/index.html">Developer Stories</a></li>
417              </ul>
418            </li>
419          </ul>
420        </div><!-- /Expanded quicknav -->
421      </div><!-- end header-wrap.wrap -->
422    </div><!-- end header -->
423
424
425    <!-- Secondary x-nav -->
426    <div id="nav-x">
427        <div class="wrap" style="position:relative;z-index:1">
428
429
430
431
432
433            <ul class="nav-x col-9 develop" style="width:100%">
434                <li class="training"><a href="/training/index.html"
435                  zh-tw-lang="訓練課程"
436                  zh-cn-lang="培训"
437                  ru-lang="Курсы"
438                  ko-lang="교육"
439                  ja-lang="トレーニング"
440                  es-lang="Capacitación"
441                  >Training</a></li>
442                <li class="guide"><a href="/guide/index.html"
443                  zh-tw-lang="API 指南"
444                  zh-cn-lang="API 指南"
445                  ru-lang="Руководства по API"
446                  ko-lang="API 가이드"
447                  ja-lang="API ガイド"
448                  es-lang="Guías de la API"
449                  >API Guides</a></li>
450                <li class="reference"><a href="/reference/packages.html"
451                  zh-tw-lang="參考資源"
452                  zh-cn-lang="参考"
453                  ru-lang="Справочник"
454                  ko-lang="참조문서"
455                  ja-lang="リファレンス"
456                  es-lang="Referencia"
457                  >Reference</a></li>
458                <li class="tools"><a href="/sdk/index.html"
459                  zh-tw-lang="相關工具"
460                  zh-cn-lang="工具"
461                  ru-lang="Инструменты"
462                  ko-lang="도구"
463                  ja-lang="ツール"
464                  es-lang="Herramientas"
465                  >Tools</a></li>
466                <li class="google"><a href="/google/index.html"
467                  >Google Services</a>
468                </li>
469
470                  <li class="samples"><a href="/samples/index.html"
471                    >Samples</a>
472                  </li>
473
474            </ul>
475        </div>
476    </div>
477    <!-- /Sendondary x-nav DEVELOP -->
478
479
480
481    <div id="searchResults" class="wrap" style="display:none;">
482      <h2 id="searchTitle">Results</h2>
483      <div id="leftSearchControl" class="search-control">Loading...</div>
484    </div>
485  </div> <!--end header-wrapper -->
486
487  <div id="sticky-header">
488    <div>
489      <a class="logo" href="#top"></a>
490      <a class="top" href="#top"></a>
491      <ul class="breadcrumb">
492
493        <li class="current">GoogleCloudMessaging</li>
494      </ul>
495    </div>
496  </div>
497
498
499
500
501
502
503  <div class="wrap clearfix" id="body-content">
504    <div class="col-4" id="side-nav" itemscope itemtype="http://schema.org/SiteNavigationElement">
505      <div id="devdoc-nav" class="scroll-pane">
506
507
508
509<ul id="nav">
510
511  <li class="nav-section">
512    <div class="nav-section-header empty"><a href="/google/index.html">
513          <span class="en">Overview</span>
514      </a></div>
515  </li>
516
517  <li class="nav-section">
518    <div class="nav-section-header empty"><a href="/google/play-services/games.html">
519          <span class="en">Games</span>
520      </a></div>
521  </li>
522  <li class="nav-section">
523    <div class="nav-section-header empty"><a href="/google/play-services/location.html">
524          <span class="en">Location</span>
525      </a></div>
526  </li>
527  <li class="nav-section">
528    <div class="nav-section-header empty"><a href="/google/play-services/plus.html">
529          <span class="en">Google+</span>
530                </a></div>
531  </li>
532  <li class="nav-section">
533    <div class="nav-section-header empty"><a href="/google/play-services/maps.html">
534          <span class="en">Maps</span>
535      </a></div>
536  </li>
537  <li class="nav-section">
538    <div class="nav-section-header empty"><a href="/google/play-services/drive.html">
539          <span class="en">Drive</span>
540      </a></div>
541  </li>
542  <li class="nav-section">
543    <div class="nav-section-header empty"><a href="/google/play-services/cast.html">
544          <span class="en">Cast</span>
545      </a></div>
546  </li>
547  <li class="nav-section">
548    <div class="nav-section-header"><a href="/google/play-services/ads.html">
549      <span class="en">Ads</span></a>
550    </div>
551    <ul>
552      <li><a href="/google/play-services/id.html">
553          <span class="en">Advertising ID</span></a>
554      </li>
555    </ul>
556  </li>
557  <li class="nav-section">
558    <div class="nav-section-header empty"><a href="/google/play-services/wallet.html">
559          <span class="en">Wallet</span>
560      </a></div>
561  </li>
562
563
564  <li class="nav-section">
565    <div class="nav-section-header"><a href="/google/play-services/index.html">
566      <span class="en">Google Play Services</span></a>
567    </div>
568    <ul>
569      <li><a href="/google/play-services/setup.html">
570          <span class="en">Setting Up Google Play Services</span></a>
571      </li>
572      <li class="nav-section">
573        <div class="nav-section-header"><a href="/google/auth/api-client.html">
574          <span class="en">Accessing Google APIs</span></a>
575        </div>
576        <ul>
577          <li>
578            <a href="/google/auth/http-auth.html">
579              <span class="en">Authorizing with Google for REST APIs</span>
580            </a>
581          </li>
582        </ul>
583      </li>
584      <li id="gms-tree-list" class="nav-section">
585        <div class="nav-section-header">
586          <a href="/reference/gms-packages.html">
587            <span class="en">Reference</span>
588          </a>
589        <div>
590      </li>
591    </ul>
592  </li>
593
594
595  <li class="nav-section">
596    <div class="nav-section-header"><a href="/google/play/billing/index.html">
597      <span class="en">Google Play In-app Billing</span></a>
598    </div>
599    <ul>
600      <li><a href="/google/play/billing/billing_overview.html">
601              <span class="en">Overview</span></a>
602      </li>
603      <li class="nav-section"><div class="nav-section-header"><a href="/google/play/billing/api.html">
604              <span class="en">Version 3 API</span></a></div>
605              <ul>
606              <li><a href="/google/play/billing/billing_integrate.html">
607              <span class="en">Implementing the API</span></a></li>
608              <li><a href="/google/play/billing/billing_reference.html">
609              <span class="en">Reference</span></a></li>
610              </ul>
611      </li>
612      <li class="nav-section"><div class="nav-section-header"><a href="/google/play/billing/v2/api.html">
613              <span class="en">Version 2 API</span></a></div>
614              <ul>
615              <li><a href="/google/play/billing/v2/billing_integrate.html">
616              <span class="en">Implementing the API</span></a></li>
617              <li><a href="/google/play/billing/v2/billing_subscriptions.html">
618              <span class="en">Subscriptions</span></a></li>
619              <li><a href="/google/play/billing/v2/billing_reference.html">
620              <span class="en">Reference</span></a></li>
621              </ul>
622      </li>
623      <li><a href="/google/play/billing/billing_subscriptions.html">
624              <span class="en">Subscriptions</span></a>
625      </li>
626      <li><a href="/google/play/billing/billing_best_practices.html">
627              <span class="en">Security and Design</span></a>
628      </li>
629      <li><a href="/google/play/billing/billing_testing.html">
630              <span class="en">Testing In-app Billing</span></a>
631      </li>
632      <li><a href="/google/play/billing/billing_admin.html">
633              <span class="en">Administering In-app Billing</span></a>
634      </li>
635      <li><a href="/google/play/billing/versions.html">
636              <span class="en">Version Notes</span></a>
637      </li>
638    </ul>
639  </li>
640
641
642
643   <li class="nav-section">
644      <div class="nav-section-header"><a href="/google/gcm/index.html">
645        <span class="en">Google Cloud Messaging</span></a>
646      </div>
647      <ul>
648        <li><a href="/google/gcm/gcm.html">
649            <span class="en">Overview</span></a>
650        </li>
651        <li><a href="/google/gcm/gs.html">
652            <span class="en">Getting Started</span></a>
653        </li>
654        <li><a href="/google/gcm/client.html">
655            <span class="en">Implementing GCM Client</span></a>
656        </li>
657        <li class="nav-section"><div class="nav-section-header"><a href="/google/gcm/server.html">
658              <span class="en">Implementing GCM Server</span></a></div>
659              <ul>
660              <li><a href="/google/gcm/ccs.html">
661              <span class="en">CCS (XMPP)</span></a></li>
662              <li><a href="/google/gcm/http.html">
663              <span class="en">HTTP</span></a></li>
664              </ul>
665        </li>
666        <li><a href="/google/gcm/notifications.html">
667              <span class="en">User Notifications</span></a>
668        </li>
669        <li><a href="/google/gcm/adv.html">
670            <span class="en">Advanced Topics</span></a>
671        </li>
672        <li><a href="/google/gcm/c2dm.html">
673            <span class="en">Migration</span></a>
674        </li>
675        <li id="gcm-tree-list" class="nav-section">
676          <div class="nav-section-header">
677            <a href="/reference/gcm-packages.html">
678              <span class="en">Reference</span>
679            </a>
680          <div>
681        </li>
682      </ul>
683  </li>
684
685  <li class="nav-section">
686  <div class="nav-section-header empty"><a href="/google/gcs/index.html">
687        <span class="en">Google Cloud Save</span></a>
688      </div>
689  </li>
690
691  <li class="nav-section">
692    <div class="nav-section-header"><a href="/google/play/dist.html">
693      <span class="en">Google Play Distribution</span></a>
694    </div>
695    <ul>
696      <li><a href="/google/play/filters.html">
697          <span class="en">Filters on Google Play</span></a>
698      </li>
699      <li><a href="/google/play/billing/gp-purchase-status-api.html">
700              <span class="en">Google Play Developer API</span></a>
701      </li>
702      <li><a href="/google/play/publishing/multiple-apks.html">
703          <span class="en">Multiple APK Support</span></a>
704      </li>
705      <li><a href="/google/play/expansion-files.html">
706          <span class="en">APK Expansion Files</span></a>
707      </li>
708      <li class="nav-section">
709        <div class="nav-section-header"><a href="/google/play/licensing/index.html">
710          <span class="en">Application Licensing</span></a>
711        </div>
712        <ul>
713          <li><a href="/google/play/licensing/overview.html">
714              <span class="en">Licensing Overview</span></a>
715          </li>
716          <li><a href="/google/play/licensing/setting-up.html">
717              <span class="en">Setting Up for Licensing</span></a>
718          </li>
719          <li><a href="/google/play/licensing/adding-licensing.html">
720              <span class="en">Adding Licensing to Your App</span></a>
721          </li>
722          <li><a href="/google/play/licensing/licensing-reference.html">
723              <span class="en">Licensing Reference</span></a>
724          </li>
725        </ul>
726      </li>
727
728  <li class="nav-section">
729    <div class="nav-section-header"><a href="/google/backup/index.html">
730      Android Backup Service</a>
731    </div>
732    <ul>
733      <li><a href="/google/backup/signup.html">
734          Register</a>
735      </li>
736    </ul>
737  </li>
738
739  </ul>
740
741</li>
742
743
744
745</ul>
746
747<script type="text/javascript">
748<!--
749    buildToggleLists();
750    changeNavLang(getLangPref());
751//-->
752</script>
753
754
755
756
757      </div>
758      <script type="text/javascript">
759       showGoogleRefTree();
760
761      </script>
762    </div> <!-- end side-nav -->
763    <script>
764      $(document).ready(function() {
765        scrollIntoView("devdoc-nav");
766        });
767    </script>
768
769
770
771
772
773
774<div class="col-12"  id="doc-col">
775
776<div id="api-info-block">
777
778
779
780
781
782
783
784
785
786
787
788<div class="sum-details-links">
789
790Summary:
791
792
793
794
795
796  <a href="#constants">Constants</a>
797
798
799
800
801
802
803  &#124; <a href="#pubctors">Ctors</a>
804
805
806
807
808  &#124; <a href="#pubmethods">Methods</a>
809
810
811
812
813  &#124; <a href="#inhmethods">Inherited Methods</a>
814
815&#124; <a href="#" onclick="return toggleAllClassInherited()" id="toggleAllClassInherited">[Expand All]</a>
816
817</div><!-- end sum-details-links -->
818<div class="api-level">
819
820
821
822
823</div>
824</div><!-- end api-info-block -->
825
826
827<!-- ======== START OF CLASS DATA ======== -->
828
829<div id="jd-header">
830    public
831
832
833
834    class
835<h1 itemprop="name">GoogleCloudMessaging</h1>
836
837
838
839
840    extends Object<br/>
841
842
843
844
845
846
847
848
849
850
851
852
853</div><!-- end header -->
854
855<div id="naMessage"></div>
856
857<div id="jd-content" class="api apilevel-">
858<table class="jd-inheritance-table">
859
860
861    <tr>
862
863        <td colspan="2" class="jd-inheritance-class-cell">java.lang.Object</td>
864    </tr>
865
866
867    <tr>
868
869            <td class="jd-inheritance-space">&nbsp;&nbsp;&nbsp;&#x21b3;</td>
870
871        <td colspan="1" class="jd-inheritance-class-cell">com.google.android.gms.gcm.GoogleCloudMessaging</td>
872    </tr>
873
874
875</table>
876
877
878
879
880
881
882
883<div class="jd-descr">
884
885
886<h2>Class Overview</h2>
887<p itemprop="articleBody"><p>The class you use to write a GCM-enabled client application that runs on an Android device.
888 Client applications can receive GCM messages and optionally send messages of their own back to
889 the server.
890
891 <p>This class requires Google Play services version 3.1 or higher. For a
892 detailed discussion of how to write a GCM client app, see
893 <a href="http://developer.android.com/google/gcm/client.html">
894 Implementing GCM Client</a>.
895
896 <p>To send or receive messages, your application first needs to get a registration ID. The
897 registration ID identifies the device and application, and also determines which 3rd-party
898 application servers are allowed to send messages to this application instance.
899
900 <p>To get a registration ID, you must supply one or more sender IDs. A sender ID is a project
901 number you acquire from the API console, as described in
902 <a href="http://developer.android.com/google/gcm/gs.html">Getting Started</a>. The sender ID is
903 used in the registration process to identify a 3rd-party application server that is permitted to
904 send messages to the device. The following snippet shows you how to call the
905 <code><a href="/reference/com/google/android/gms/gcm/GoogleCloudMessaging.html#register(java.lang.String...)">register()</a></code> method. For a more comprehensive example, see
906 <a href="http://developer.android.com/google/gcm/client.html">Implementing GCM Client</a>.
907
908 <pre>
909 String SENDER_ID = "My-Sender-ID";
910 GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context);
911 String registrationId = gcm.register(SENDER_ID);
912 // Upload the registration ID to your own server
913 // The request to your server should be authenticated if your app is using accounts.
914 </pre>
915
916 <p>In order to receive GCM messages, you need to declare a permission and a
917 <code>BroadcastReceiver</code> in your manifest. This is a backward-compatible subset of what was
918 required in previous versions of GCM.
919
920 <p>To allow the application to use GCM, add this permission to the manifest:
921
922 <pre>&lt;uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" /&gt;</pre>
923
924 <p>GCM delivers messages as a broadcast. The receivers must be registered in the manifest in
925 order to wake up the application.
926
927 <p>The <code>com.google.android.c2dm.permission.SEND permission</code> is held by Google Play
928 services. This prevents other code from invoking the broadcast receiver. Here is an excerpt
929 from a sample manifest:
930
931 <pre>
932 &lt;receiver android:name=".MyReceiver" android:exported="true"
933     android:permission="com.google.android.c2dm.permission.SEND" &gt;
934     &lt;intent-filter&gt;
935        &lt;action android:name="com.google.android.c2dm.intent.RECEIVE" /&gt;
936        &lt;category android:name="YOUR_PACKAGE_NAME" /&gt;
937     &lt;/intent-filter&gt;
938 &lt;/receiver&gt;</pre>
939
940 <p>When a GCM connection server delivers the message to your client app, the
941 <code>BroadcastReceiver</code> receives the message as an intent. You can either process the
942 intent in the <code>BroadcastReceiver</code>, or you can pass off the work of processing the
943 intent to a service (typically, an <code>IntentService</code>). If you use a service, your
944 broadcast receiver should be an instance of <code>WakefulBroadcastReceiver</code>, to hold a
945 wake lock while the service is doing its work.
946
947 <p>When processing the intent GCM passes into your app's broadcast receiver, you can determine
948 the message type by calling <code><a href="/reference/com/google/android/gms/gcm/GoogleCloudMessaging.html#getMessageType(android.content.Intent)">getMessageType(intent)</a></code>. For example:
949
950 <pre>
951 GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
952 String messageType = gcm.getMessageType(intent);
953 ...
954 // Filter messages based on message type. It is likely that GCM will be extended in the future
955 // with new message types, so just ignore message types you're not interested in, or that you
956 // don't recognize.
957 if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) {
958    // It's an error.
959 } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) {
960    // Deleted messages on the server.
961 } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) {
962    // It's a regular GCM message, do some work.
963 }
964 </pre>
965
966 <p>If you are using the XMPP-based
967 <a href="http://developer.android.com/google/gcm/ccs.html">Cloud Connection Server</a>, your
968 client app can send upstream messages back to the server. For example:
969
970 <pre>
971 gcm.send(SENDER_ID + "&#64;gcm.googleapis.com", id, data);
972 </pre>
973
974 For a more details, see
975 <a href="http://developer.android.com/google/gcm/client.html">Implementing GCM Client</a>.
976</p>
977
978
979
980
981
982</div><!-- jd-descr -->
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999<div class="jd-descr">
1000
1001
1002<h2>Summary</h2>
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016<!-- =========== ENUM CONSTANT SUMMARY =========== -->
1017<table id="constants" class="jd-sumtable"><tr><th colspan="12">Constants</th></tr>
1018
1019
1020
1021    <tr class="alt-color api apilevel-" >
1022        <td class="jd-typecol">String</td>
1023        <td class="jd-linkcol"><a href="/reference/com/google/android/gms/gcm/GoogleCloudMessaging.html#ERROR_MAIN_THREAD">ERROR_MAIN_THREAD</a></td>
1024        <td class="jd-descrcol" width="100%">
1025          The GCM <code><a href="/reference/com/google/android/gms/gcm/GoogleCloudMessaging.html#register(java.lang.String...)">register()</a></code> and <code><a href="/reference/com/google/android/gms/gcm/GoogleCloudMessaging.html#unregister()">unregister()</a></code> methods are
1026 blocking.
1027
1028
1029
1030        </td>
1031    </tr>
1032
1033
1034    <tr class=" api apilevel-" >
1035        <td class="jd-typecol">String</td>
1036        <td class="jd-linkcol"><a href="/reference/com/google/android/gms/gcm/GoogleCloudMessaging.html#ERROR_SERVICE_NOT_AVAILABLE">ERROR_SERVICE_NOT_AVAILABLE</a></td>
1037        <td class="jd-descrcol" width="100%">
1038          The device can't read the response, or there was a 500/503 from the
1039 server that can be retried later.
1040
1041
1042
1043        </td>
1044    </tr>
1045
1046
1047    <tr class="alt-color api apilevel-" >
1048        <td class="jd-typecol">String</td>
1049        <td class="jd-linkcol"><a href="/reference/com/google/android/gms/gcm/GoogleCloudMessaging.html#MESSAGE_TYPE_DELETED">MESSAGE_TYPE_DELETED</a></td>
1050        <td class="jd-descrcol" width="100%">
1051          Returned by <code><a href="/reference/com/google/android/gms/gcm/GoogleCloudMessaging.html#getMessageType(android.content.Intent)">getMessageType(Intent)</a></code> to indicate that the server deleted
1052 some pending messages because they were collapsible.
1053
1054
1055
1056        </td>
1057    </tr>
1058
1059
1060    <tr class=" api apilevel-" >
1061        <td class="jd-typecol">String</td>
1062        <td class="jd-linkcol"><a href="/reference/com/google/android/gms/gcm/GoogleCloudMessaging.html#MESSAGE_TYPE_MESSAGE">MESSAGE_TYPE_MESSAGE</a></td>
1063        <td class="jd-descrcol" width="100%">
1064          Returned by <code><a href="/reference/com/google/android/gms/gcm/GoogleCloudMessaging.html#getMessageType(android.content.Intent)">getMessageType(Intent)</a></code> to indicate a regular message.
1065
1066
1067
1068        </td>
1069    </tr>
1070
1071
1072    <tr class="alt-color api apilevel-" >
1073        <td class="jd-typecol">String</td>
1074        <td class="jd-linkcol"><a href="/reference/com/google/android/gms/gcm/GoogleCloudMessaging.html#MESSAGE_TYPE_SEND_ERROR">MESSAGE_TYPE_SEND_ERROR</a></td>
1075        <td class="jd-descrcol" width="100%">
1076          Returned by <code><a href="/reference/com/google/android/gms/gcm/GoogleCloudMessaging.html#getMessageType(android.content.Intent)">getMessageType(Intent)</a></code> to indicate a send error.
1077
1078
1079
1080        </td>
1081    </tr>
1082
1083
1084
1085</table>
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098<!-- ======== CONSTRUCTOR SUMMARY ======== -->
1099<table id="pubctors" class="jd-sumtable"><tr><th colspan="12">Public Constructors</th></tr>
1100
1101
1102
1103
1104    <tr class="alt-color api apilevel-" >
1105        <td class="jd-typecol"><nobr>
1106
1107
1108
1109
1110
1111            </nobr>
1112        </td>
1113        <td class="jd-linkcol" width="100%"><nobr>
1114        <span class="sympad"><a href="/reference/com/google/android/gms/gcm/GoogleCloudMessaging.html#GoogleCloudMessaging()">GoogleCloudMessaging</a></span>()</nobr>
1115
1116  </td></tr>
1117
1118
1119
1120</table>
1121
1122
1123
1124
1125
1126
1127<!-- ========== METHOD SUMMARY =========== -->
1128<table id="pubmethods" class="jd-sumtable"><tr><th colspan="12">Public Methods</th></tr>
1129
1130
1131
1132
1133    <tr class="alt-color api apilevel-" >
1134        <td class="jd-typecol"><nobr>
1135
1136
1137
1138
1139
1140            void</nobr>
1141        </td>
1142        <td class="jd-linkcol" width="100%"><nobr>
1143        <span class="sympad"><a href="/reference/com/google/android/gms/gcm/GoogleCloudMessaging.html#close()">close</a></span>()</nobr>
1144
1145        <div class="jd-descrdiv">
1146          Must be called when your application is done using GCM, to release
1147 internal resources.
1148
1149
1150
1151        </div>
1152
1153  </td></tr>
1154
1155
1156
1157    <tr class=" api apilevel-" >
1158        <td class="jd-typecol"><nobr>
1159
1160            synchronized
1161
1162            static
1163
1164            <a href="/reference/com/google/android/gms/gcm/GoogleCloudMessaging.html">GoogleCloudMessaging</a></nobr>
1165        </td>
1166        <td class="jd-linkcol" width="100%"><nobr>
1167        <span class="sympad"><a href="/reference/com/google/android/gms/gcm/GoogleCloudMessaging.html#getInstance(android.content.Context)">getInstance</a></span>(Context context)</nobr>
1168
1169        <div class="jd-descrdiv">
1170          Return the singleton instance of GCM.
1171
1172
1173
1174        </div>
1175
1176  </td></tr>
1177
1178
1179
1180    <tr class="alt-color api apilevel-" >
1181        <td class="jd-typecol"><nobr>
1182
1183
1184
1185
1186
1187            String</nobr>
1188        </td>
1189        <td class="jd-linkcol" width="100%"><nobr>
1190        <span class="sympad"><a href="/reference/com/google/android/gms/gcm/GoogleCloudMessaging.html#getMessageType(android.content.Intent)">getMessageType</a></span>(Intent intent)</nobr>
1191
1192        <div class="jd-descrdiv">
1193          Return the message type from an intent passed into a client app's broadcast receiver.
1194
1195
1196
1197        </div>
1198
1199  </td></tr>
1200
1201
1202
1203    <tr class=" api apilevel-" >
1204        <td class="jd-typecol"><nobr>
1205
1206
1207
1208
1209
1210            String</nobr>
1211        </td>
1212        <td class="jd-linkcol" width="100%"><nobr>
1213        <span class="sympad"><a href="/reference/com/google/android/gms/gcm/GoogleCloudMessaging.html#register(java.lang.String...)">register</a></span>(String... senderIds)</nobr>
1214
1215        <div class="jd-descrdiv">
1216          Register the application for GCM and return the registration ID.
1217
1218
1219
1220        </div>
1221
1222  </td></tr>
1223
1224
1225
1226    <tr class="alt-color api apilevel-" >
1227        <td class="jd-typecol"><nobr>
1228
1229
1230
1231
1232
1233            void</nobr>
1234        </td>
1235        <td class="jd-linkcol" width="100%"><nobr>
1236        <span class="sympad"><a href="/reference/com/google/android/gms/gcm/GoogleCloudMessaging.html#send(java.lang.String, java.lang.String, long, android.os.Bundle)">send</a></span>(String to, String msgId, long timeToLive, Bundle data)</nobr>
1237
1238        <div class="jd-descrdiv">
1239          Send an upstream ("device to cloud") message.
1240
1241
1242
1243        </div>
1244
1245  </td></tr>
1246
1247
1248
1249    <tr class=" api apilevel-" >
1250        <td class="jd-typecol"><nobr>
1251
1252
1253
1254
1255
1256            void</nobr>
1257        </td>
1258        <td class="jd-linkcol" width="100%"><nobr>
1259        <span class="sympad"><a href="/reference/com/google/android/gms/gcm/GoogleCloudMessaging.html#send(java.lang.String, java.lang.String, android.os.Bundle)">send</a></span>(String to, String msgId, Bundle data)</nobr>
1260
1261        <div class="jd-descrdiv">
1262          Send an upstream ("device to cloud") message.
1263
1264
1265
1266        </div>
1267
1268  </td></tr>
1269
1270
1271
1272    <tr class="alt-color api apilevel-" >
1273        <td class="jd-typecol"><nobr>
1274
1275
1276
1277
1278
1279            void</nobr>
1280        </td>
1281        <td class="jd-linkcol" width="100%"><nobr>
1282        <span class="sympad"><a href="/reference/com/google/android/gms/gcm/GoogleCloudMessaging.html#unregister()">unregister</a></span>()</nobr>
1283
1284        <div class="jd-descrdiv">
1285          Unregister the application.
1286
1287
1288
1289        </div>
1290
1291  </td></tr>
1292
1293
1294
1295</table>
1296
1297
1298
1299
1300
1301
1302
1303<!-- ========== METHOD SUMMARY =========== -->
1304<table id="inhmethods" class="jd-sumtable"><tr><th>
1305  <a href="#" class="toggle-all" onclick="return toggleAllInherited(this, null)">[Expand]</a>
1306  <div style="clear:left;">Inherited Methods</div></th></tr>
1307
1308
1309<tr class="api apilevel-" >
1310<td colspan="12">
1311  <a href="#" onclick="return toggleInherited(this, null)" id="inherited-methods-java.lang.Object" class="jd-expando-trigger closed"
1312          ><img id="inherited-methods-java.lang.Object-trigger"
1313          src="/assets/images/triangle-closed.png"
1314          class="jd-expando-trigger-img" /></a>
1315From class
1316
1317  java.lang.Object
1318
1319<div id="inherited-methods-java.lang.Object">
1320  <div id="inherited-methods-java.lang.Object-list"
1321        class="jd-inheritedlinks">
1322  </div>
1323  <div id="inherited-methods-java.lang.Object-summary" style="display: none;">
1324    <table class="jd-sumtable-expando">
1325
1326
1327
1328
1329    <tr class="alt-color api apilevel-" >
1330        <td class="jd-typecol"><nobr>
1331
1332
1333
1334
1335
1336            Object</nobr>
1337        </td>
1338        <td class="jd-linkcol" width="100%"><nobr>
1339        <span class="sympad">clone</span>()</nobr>
1340
1341  </td></tr>
1342
1343
1344
1345    <tr class=" api apilevel-" >
1346        <td class="jd-typecol"><nobr>
1347
1348
1349
1350
1351
1352            boolean</nobr>
1353        </td>
1354        <td class="jd-linkcol" width="100%"><nobr>
1355        <span class="sympad">equals</span>(Object arg0)</nobr>
1356
1357  </td></tr>
1358
1359
1360
1361    <tr class="alt-color api apilevel-" >
1362        <td class="jd-typecol"><nobr>
1363
1364
1365
1366
1367
1368            void</nobr>
1369        </td>
1370        <td class="jd-linkcol" width="100%"><nobr>
1371        <span class="sympad">finalize</span>()</nobr>
1372
1373  </td></tr>
1374
1375
1376
1377    <tr class=" api apilevel-" >
1378        <td class="jd-typecol"><nobr>
1379
1380
1381            final
1382
1383
1384            Class&lt;?&gt;</nobr>
1385        </td>
1386        <td class="jd-linkcol" width="100%"><nobr>
1387        <span class="sympad">getClass</span>()</nobr>
1388
1389  </td></tr>
1390
1391
1392
1393    <tr class="alt-color api apilevel-" >
1394        <td class="jd-typecol"><nobr>
1395
1396
1397
1398
1399
1400            int</nobr>
1401        </td>
1402        <td class="jd-linkcol" width="100%"><nobr>
1403        <span class="sympad">hashCode</span>()</nobr>
1404
1405  </td></tr>
1406
1407
1408
1409    <tr class=" api apilevel-" >
1410        <td class="jd-typecol"><nobr>
1411
1412
1413            final
1414
1415
1416            void</nobr>
1417        </td>
1418        <td class="jd-linkcol" width="100%"><nobr>
1419        <span class="sympad">notify</span>()</nobr>
1420
1421  </td></tr>
1422
1423
1424
1425    <tr class="alt-color api apilevel-" >
1426        <td class="jd-typecol"><nobr>
1427
1428
1429            final
1430
1431
1432            void</nobr>
1433        </td>
1434        <td class="jd-linkcol" width="100%"><nobr>
1435        <span class="sympad">notifyAll</span>()</nobr>
1436
1437  </td></tr>
1438
1439
1440
1441    <tr class=" api apilevel-" >
1442        <td class="jd-typecol"><nobr>
1443
1444
1445
1446
1447
1448            String</nobr>
1449        </td>
1450        <td class="jd-linkcol" width="100%"><nobr>
1451        <span class="sympad">toString</span>()</nobr>
1452
1453  </td></tr>
1454
1455
1456
1457    <tr class="alt-color api apilevel-" >
1458        <td class="jd-typecol"><nobr>
1459
1460
1461            final
1462
1463
1464            void</nobr>
1465        </td>
1466        <td class="jd-linkcol" width="100%"><nobr>
1467        <span class="sympad">wait</span>()</nobr>
1468
1469  </td></tr>
1470
1471
1472
1473    <tr class=" api apilevel-" >
1474        <td class="jd-typecol"><nobr>
1475
1476
1477            final
1478
1479
1480            void</nobr>
1481        </td>
1482        <td class="jd-linkcol" width="100%"><nobr>
1483        <span class="sympad">wait</span>(long arg0, int arg1)</nobr>
1484
1485  </td></tr>
1486
1487
1488
1489    <tr class="alt-color api apilevel-" >
1490        <td class="jd-typecol"><nobr>
1491
1492
1493            final
1494
1495
1496            void</nobr>
1497        </td>
1498        <td class="jd-linkcol" width="100%"><nobr>
1499        <span class="sympad">wait</span>(long arg0)</nobr>
1500
1501  </td></tr>
1502
1503
1504</table>
1505  </div>
1506</div>
1507</td></tr>
1508
1509
1510</table>
1511
1512
1513</div><!-- jd-descr (summary) -->
1514
1515<!-- Details -->
1516
1517
1518
1519
1520
1521
1522
1523
1524<!-- XML Attributes -->
1525
1526
1527<!-- Enum Values -->
1528
1529
1530<!-- Constants -->
1531
1532
1533<!-- ========= ENUM CONSTANTS DETAIL ======== -->
1534<h2>Constants</h2>
1535
1536
1537
1538
1539<A NAME="ERROR_MAIN_THREAD"></A>
1540
1541<div class="jd-details api apilevel-">
1542    <h4 class="jd-details-title">
1543      <span class="normal">
1544        public
1545        static
1546        final
1547        String
1548      </span>
1549        ERROR_MAIN_THREAD
1550    </h4>
1551      <div class="api-level">
1552
1553
1554
1555
1556      </div>
1557    <div class="jd-details-descr">
1558
1559
1560
1561
1562  <div class="jd-tagdata jd-tagdescr"><p>The GCM <code><a href="/reference/com/google/android/gms/gcm/GoogleCloudMessaging.html#register(java.lang.String...)">register()</a></code> and <code><a href="/reference/com/google/android/gms/gcm/GoogleCloudMessaging.html#unregister()">unregister()</a></code> methods are
1563 blocking. You should not run them in the main thread or in broadcast receivers.
1564</p></div>
1565
1566
1567        <div class="jd-tagdata">
1568        <span class="jd-tagtitle">Constant Value: </span>
1569        <span>
1570
1571                "MAIN_THREAD"
1572
1573        </span>
1574        </div>
1575
1576    </div>
1577</div>
1578
1579
1580
1581<A NAME="ERROR_SERVICE_NOT_AVAILABLE"></A>
1582
1583<div class="jd-details api apilevel-">
1584    <h4 class="jd-details-title">
1585      <span class="normal">
1586        public
1587        static
1588        final
1589        String
1590      </span>
1591        ERROR_SERVICE_NOT_AVAILABLE
1592    </h4>
1593      <div class="api-level">
1594
1595
1596
1597
1598      </div>
1599    <div class="jd-details-descr">
1600
1601
1602
1603
1604  <div class="jd-tagdata jd-tagdescr"><p>The device can't read the response, or there was a 500/503 from the
1605 server that can be retried later. The application should use exponential
1606 back off and retry.
1607</p></div>
1608
1609
1610        <div class="jd-tagdata">
1611        <span class="jd-tagtitle">Constant Value: </span>
1612        <span>
1613
1614                "SERVICE_NOT_AVAILABLE"
1615
1616        </span>
1617        </div>
1618
1619    </div>
1620</div>
1621
1622
1623
1624<A NAME="MESSAGE_TYPE_DELETED"></A>
1625
1626<div class="jd-details api apilevel-">
1627    <h4 class="jd-details-title">
1628      <span class="normal">
1629        public
1630        static
1631        final
1632        String
1633      </span>
1634        MESSAGE_TYPE_DELETED
1635    </h4>
1636      <div class="api-level">
1637
1638
1639
1640
1641      </div>
1642    <div class="jd-details-descr">
1643
1644
1645
1646
1647  <div class="jd-tagdata jd-tagdescr"><p>Returned by <code><a href="/reference/com/google/android/gms/gcm/GoogleCloudMessaging.html#getMessageType(android.content.Intent)">getMessageType(Intent)</a></code> to indicate that the server deleted
1648 some pending messages because they were collapsible.
1649</p></div>
1650
1651
1652        <div class="jd-tagdata">
1653        <span class="jd-tagtitle">Constant Value: </span>
1654        <span>
1655
1656                "deleted_messages"
1657
1658        </span>
1659        </div>
1660
1661    </div>
1662</div>
1663
1664
1665
1666<A NAME="MESSAGE_TYPE_MESSAGE"></A>
1667
1668<div class="jd-details api apilevel-">
1669    <h4 class="jd-details-title">
1670      <span class="normal">
1671        public
1672        static
1673        final
1674        String
1675      </span>
1676        MESSAGE_TYPE_MESSAGE
1677    </h4>
1678      <div class="api-level">
1679
1680
1681
1682
1683      </div>
1684    <div class="jd-details-descr">
1685
1686
1687
1688
1689  <div class="jd-tagdata jd-tagdescr"><p>Returned by <code><a href="/reference/com/google/android/gms/gcm/GoogleCloudMessaging.html#getMessageType(android.content.Intent)">getMessageType(Intent)</a></code> to indicate a regular message.
1690</p></div>
1691
1692
1693        <div class="jd-tagdata">
1694        <span class="jd-tagtitle">Constant Value: </span>
1695        <span>
1696
1697                "gcm"
1698
1699        </span>
1700        </div>
1701
1702    </div>
1703</div>
1704
1705
1706
1707<A NAME="MESSAGE_TYPE_SEND_ERROR"></A>
1708
1709<div class="jd-details api apilevel-">
1710    <h4 class="jd-details-title">
1711      <span class="normal">
1712        public
1713        static
1714        final
1715        String
1716      </span>
1717        MESSAGE_TYPE_SEND_ERROR
1718    </h4>
1719      <div class="api-level">
1720
1721
1722
1723
1724      </div>
1725    <div class="jd-details-descr">
1726
1727
1728
1729
1730  <div class="jd-tagdata jd-tagdescr"><p>Returned by <code><a href="/reference/com/google/android/gms/gcm/GoogleCloudMessaging.html#getMessageType(android.content.Intent)">getMessageType(Intent)</a></code> to indicate a send error.
1731 The intent includes the message ID of the message and an error code.
1732</p></div>
1733
1734
1735        <div class="jd-tagdata">
1736        <span class="jd-tagtitle">Constant Value: </span>
1737        <span>
1738
1739                "send_error"
1740
1741        </span>
1742        </div>
1743
1744    </div>
1745</div>
1746
1747
1748
1749
1750<!-- Fields -->
1751
1752
1753<!-- Public ctors -->
1754
1755
1756<!-- ========= CONSTRUCTOR DETAIL ======== -->
1757<h2>Public Constructors</h2>
1758
1759
1760
1761<A NAME="GoogleCloudMessaging()"></A>
1762
1763<div class="jd-details api apilevel-">
1764    <h4 class="jd-details-title">
1765      <span class="normal">
1766        public
1767
1768
1769
1770
1771
1772      </span>
1773      <span class="sympad">GoogleCloudMessaging</span>
1774      <span class="normal">()</span>
1775    </h4>
1776      <div class="api-level">
1777        <div></div>
1778
1779
1780
1781      </div>
1782    <div class="jd-details-descr">
1783
1784
1785
1786
1787  <div class="jd-tagdata jd-tagdescr"><p></p></div>
1788
1789    </div>
1790</div>
1791
1792
1793
1794
1795
1796<!-- ========= CONSTRUCTOR DETAIL ======== -->
1797<!-- Protected ctors -->
1798
1799
1800
1801<!-- ========= METHOD DETAIL ======== -->
1802<!-- Public methdos -->
1803
1804<h2>Public Methods</h2>
1805
1806
1807
1808<A NAME="close()"></A>
1809
1810<div class="jd-details api apilevel-">
1811    <h4 class="jd-details-title">
1812      <span class="normal">
1813        public
1814
1815
1816
1817
1818        void
1819      </span>
1820      <span class="sympad">close</span>
1821      <span class="normal">()</span>
1822    </h4>
1823      <div class="api-level">
1824        <div></div>
1825
1826
1827
1828      </div>
1829    <div class="jd-details-descr">
1830
1831
1832
1833
1834  <div class="jd-tagdata jd-tagdescr"><p>Must be called when your application is done using GCM, to release
1835 internal resources.
1836</p></div>
1837
1838    </div>
1839</div>
1840
1841
1842<A NAME="getInstance(android.content.Context)"></A>
1843
1844<div class="jd-details api apilevel-">
1845    <h4 class="jd-details-title">
1846      <span class="normal">
1847        public
1848        static
1849
1850
1851        synchronized
1852        <a href="/reference/com/google/android/gms/gcm/GoogleCloudMessaging.html">GoogleCloudMessaging</a>
1853      </span>
1854      <span class="sympad">getInstance</span>
1855      <span class="normal">(Context context)</span>
1856    </h4>
1857      <div class="api-level">
1858        <div></div>
1859
1860
1861
1862      </div>
1863    <div class="jd-details-descr">
1864
1865
1866
1867
1868  <div class="jd-tagdata jd-tagdescr"><p>Return the singleton instance of GCM.</p></div>
1869
1870    </div>
1871</div>
1872
1873
1874<A NAME="getMessageType(android.content.Intent)"></A>
1875
1876<div class="jd-details api apilevel-">
1877    <h4 class="jd-details-title">
1878      <span class="normal">
1879        public
1880
1881
1882
1883
1884        String
1885      </span>
1886      <span class="sympad">getMessageType</span>
1887      <span class="normal">(Intent intent)</span>
1888    </h4>
1889      <div class="api-level">
1890        <div></div>
1891
1892
1893
1894      </div>
1895    <div class="jd-details-descr">
1896
1897
1898
1899
1900  <div class="jd-tagdata jd-tagdescr"><p>Return the message type from an intent passed into a client app's broadcast receiver. There
1901 are two general categories of messages passed from the server: regular GCM messages,
1902 and special GCM status messages.
1903
1904 The possible types are:
1905 <ul>
1906   <li><code><a href="/reference/com/google/android/gms/gcm/GoogleCloudMessaging.html#MESSAGE_TYPE_MESSAGE">MESSAGE_TYPE_MESSAGE</a></code>&mdash;regular message from your server.
1907   </li><li><code><a href="/reference/com/google/android/gms/gcm/GoogleCloudMessaging.html#MESSAGE_TYPE_DELETED">MESSAGE_TYPE_DELETED</a></code>&mdash;special status message indicating that some
1908     messages have been collapsed by GCM.
1909   </li><li><code><a href="/reference/com/google/android/gms/gcm/GoogleCloudMessaging.html#MESSAGE_TYPE_SEND_ERROR">MESSAGE_TYPE_SEND_ERROR</a></code>&mdash;special status message indicating that
1910     there were errors sending one of the messages.
1911  </li></ul>
1912
1913 You can use this method to filter based on message type. Since it is likely that GCM will
1914 be extended in the future with new message types, just ignore any message types you're not
1915 interested in, or that you don't recognize.</p></div>
1916  <div class="jd-tagdata">
1917      <h5 class="jd-tagtitle">Returns</h5>
1918      <ul class="nolist"><li>The message type or null if the intent is not a GCM intent
1919</li></ul>
1920  </div>
1921
1922    </div>
1923</div>
1924
1925
1926<A NAME="register(java.lang.String...)"></A>
1927
1928<div class="jd-details api apilevel-">
1929    <h4 class="jd-details-title">
1930      <span class="normal">
1931        public
1932
1933
1934
1935
1936        String
1937      </span>
1938      <span class="sympad">register</span>
1939      <span class="normal">(String... senderIds)</span>
1940    </h4>
1941      <div class="api-level">
1942        <div></div>
1943
1944
1945
1946      </div>
1947    <div class="jd-details-descr">
1948
1949
1950
1951
1952  <div class="jd-tagdata jd-tagdescr"><p>Register the application for GCM and return the registration ID. You must call this once,
1953 when your application is installed, and send the returned registration ID to the server.
1954 <p>
1955 Repeated calls to this method will return the original registration ID.
1956 <p>
1957 If you want to modify the list of senders, you must call <code>unregister()</code> first.
1958 <p>
1959 Most applications use a single sender ID. You may use multiple senders if different
1960 servers may send messages to the app or for testing.</p></div>
1961  <div class="jd-tagdata">
1962      <h5 class="jd-tagtitle">Parameters</h5>
1963      <table class="jd-tagtable">
1964        <tr>
1965          <th>senderIds</td>
1966          <td>list of project numbers or Google accounts identifying who is allowed to
1967   send messages to this application.</td>
1968        </tr>
1969      </table>
1970  </div>
1971  <div class="jd-tagdata">
1972      <h5 class="jd-tagtitle">Returns</h5>
1973      <ul class="nolist"><li>registration id
1974</li></ul>
1975  </div>
1976  <div class="jd-tagdata">
1977      <h5 class="jd-tagtitle">Throws</h5>
1978      <table class="jd-tagtable">
1979        <tr>
1980            <th>IOException</td>
1981            <td></td>
1982        </tr>
1983      </table>
1984  </div>
1985
1986    </div>
1987</div>
1988
1989
1990<A NAME="send(java.lang.String, java.lang.String, long, android.os.Bundle)"></A>
1991
1992<div class="jd-details api apilevel-">
1993    <h4 class="jd-details-title">
1994      <span class="normal">
1995        public
1996
1997
1998
1999
2000        void
2001      </span>
2002      <span class="sympad">send</span>
2003      <span class="normal">(String to, String msgId, long timeToLive, Bundle data)</span>
2004    </h4>
2005      <div class="api-level">
2006        <div></div>
2007
2008
2009
2010      </div>
2011    <div class="jd-details-descr">
2012
2013
2014
2015
2016  <div class="jd-tagdata jd-tagdescr"><p>Send an upstream ("device to cloud") message. You can only use the upstream feature
2017 if your GCM implementation uses the XMPP-based
2018 <a href="http://developer.android.com/google/gcm/ccs.html">Cloud Connection Server</a>.
2019
2020 The current limits for max storage time and number of outstanding messages per
2021 application are documented in the
2022 <a href="http://developer.android.com/google/gcm/index.html">GCM Developers Guide</a>.</p></div>
2023  <div class="jd-tagdata">
2024      <h5 class="jd-tagtitle">Parameters</h5>
2025      <table class="jd-tagtable">
2026        <tr>
2027          <th>to</td>
2028          <td>string identifying the receiver of the message. For GCM projects IDs
2029   the value is <code>SENDER_ID@gcm.googleapis.com</code>. The <code>SENDER_ID</code>
2030   should be one of the sender IDs used in <code>register()</code>.</td>
2031        </tr>
2032        <tr>
2033          <th>msgId</td>
2034          <td>ID of the message. This is generated by the application. It must be
2035   unique for each message. This allows error callbacks and debugging.</td>
2036        </tr>
2037        <tr>
2038          <th>timeToLive</td>
2039          <td>If 0, we'll attempt to send immediately and return an
2040   error if we're not connected. Otherwise, the message will be queued.
2041   As for server-side messages, we don't return an error if the message has been
2042   dropped because of TTL&mdash;this can happen on the server side, and it would require
2043   extra communication.</td>
2044        </tr>
2045        <tr>
2046          <th>data</td>
2047          <td>key/value pairs to be sent. Values must be String, any other type will
2048   be ignored.</td>
2049        </tr>
2050      </table>
2051  </div>
2052  <div class="jd-tagdata">
2053      <h5 class="jd-tagtitle">Throws</h5>
2054      <table class="jd-tagtable">
2055        <tr>
2056            <th>IllegalArgumentException</td>
2057            <td></td>
2058        </tr>
2059        <tr>
2060            <th>IOException</td>
2061            <td></td>
2062        </tr>
2063      </table>
2064  </div>
2065
2066    </div>
2067</div>
2068
2069
2070<A NAME="send(java.lang.String, java.lang.String, android.os.Bundle)"></A>
2071
2072<div class="jd-details api apilevel-">
2073    <h4 class="jd-details-title">
2074      <span class="normal">
2075        public
2076
2077
2078
2079
2080        void
2081      </span>
2082      <span class="sympad">send</span>
2083      <span class="normal">(String to, String msgId, Bundle data)</span>
2084    </h4>
2085      <div class="api-level">
2086        <div></div>
2087
2088
2089
2090      </div>
2091    <div class="jd-details-descr">
2092
2093
2094
2095
2096  <div class="jd-tagdata jd-tagdescr"><p>Send an upstream ("device to cloud") message. You can only use the upstream feature
2097 if your GCM implementation uses the XMPP-based
2098 <a href="http://developer.android.com/google/gcm/ccs.html">Cloud Connection Server</a>.
2099
2100 The message will be queued if we don't have an active connection for the max interval.</p></div>
2101  <div class="jd-tagdata">
2102      <h5 class="jd-tagtitle">Parameters</h5>
2103      <table class="jd-tagtable">
2104        <tr>
2105          <th>to</td>
2106          <td>string identifying the receiver of the message. For GCM project IDs
2107   the value is <code>SENDER_ID@gcm.googleapis.com</code>. The <code>SENDER_ID</code>
2108   should be one of the sender IDs used in <code>register()</code>.</td>
2109        </tr>
2110        <tr>
2111          <th>msgId</td>
2112          <td>ID of the message. This is generated by the application. It must be
2113   unique for each message. This allows error callbacks and debugging.</td>
2114        </tr>
2115        <tr>
2116          <th>data</td>
2117          <td>key/value pairs to be sent. Values must be String&mdash;any other type will
2118   be ignored.</td>
2119        </tr>
2120      </table>
2121  </div>
2122  <div class="jd-tagdata">
2123      <h5 class="jd-tagtitle">Throws</h5>
2124      <table class="jd-tagtable">
2125        <tr>
2126            <th></td>
2127            <td>IllegalArgumentException</td>
2128        </tr>
2129        <tr>
2130            <th>IOException</td>
2131            <td></td>
2132        </tr>
2133      </table>
2134  </div>
2135
2136    </div>
2137</div>
2138
2139
2140<A NAME="unregister()"></A>
2141
2142<div class="jd-details api apilevel-">
2143    <h4 class="jd-details-title">
2144      <span class="normal">
2145        public
2146
2147
2148
2149
2150        void
2151      </span>
2152      <span class="sympad">unregister</span>
2153      <span class="normal">()</span>
2154    </h4>
2155      <div class="api-level">
2156        <div></div>
2157
2158
2159
2160      </div>
2161    <div class="jd-details-descr">
2162
2163
2164
2165
2166  <div class="jd-tagdata jd-tagdescr"><p>Unregister the application. Calling <code>unregister()</code> stops any
2167 messages from the server. This is a blocking call&mdash;you shouldn't call
2168 it from the UI thread.
2169
2170 You should rarely (if ever) need to call this method. Not only is it
2171 expensive in terms of resources, but it invalidates your registration ID,
2172 which you should never change unnecessarily. A better approach is to simply
2173 have your server stop sending messages. Only use unregister if you want
2174 to change your sender ID.</p></div>
2175  <div class="jd-tagdata">
2176      <h5 class="jd-tagtitle">Throws</h5>
2177      <table class="jd-tagtable">
2178        <tr>
2179            <th>IOException</td>
2180            <td>if we can't connect to server to unregister.
2181</td>
2182        </tr>
2183      </table>
2184  </div>
2185
2186    </div>
2187</div>
2188
2189
2190
2191
2192
2193<!-- ========= METHOD DETAIL ======== -->
2194
2195
2196
2197<!-- ========= END OF CLASS DATA ========= -->
2198<A NAME="navbar_top"></A>
2199
2200<div id="footer" class="wrap" >
2201
2202
2203  <div id="copyright">
2204
2205  Except as noted, this content is licensed under <a
2206  href="http://www.apache.org/licenses/LICENSE-2.0">Apache 2.0</a>.
2207  For details and restrictions, see the <a href="/license.html">
2208  Content License</a>.
2209  </div>
2210  <div id="build_info">
2211
2212<script src="/timestamp.js" type="text/javascript"></script>
2213<script>document.write(BUILD_TIMESTAMP)</script>
2214
2215  </div>
2216
2217
2218  <div id="footerlinks">
2219
2220  <p>
2221    <a href="/about/index.html">About Android</a>&nbsp;&nbsp;|&nbsp;
2222    <a href="/legal.html">Legal</a>&nbsp;&nbsp;|&nbsp;
2223    <a href="/support.html">Support</a>
2224  </p>
2225  </div>
2226
2227</div> <!-- end footer -->
2228</div> <!-- jd-content -->
2229
2230</div><!-- end doc-content -->
2231
2232</div> <!-- end body-content -->
2233
2234
2235
2236
2237
2238
2239</body>
2240</html>
2241