\n\u003Cuses-permission android:name=\"com.synyx.cloudmessagetest.permission.C2D_MESSAGE\"/>\n \u003C!-- App receives GCM messages. -->\n\u003Cuses-permission android:name=\"com.google.android.c2dm.permission.RECEIVE\"/>\n \u003C!-- GCM connects to Google Services. -->\n\u003Cuses-permission android:name=\"android.permission.INTERNET\"/>\n \u003C!-- GCM requires a Google account. -->\n\u003Cuses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>\n \u003C!-- Keeps the processor from sleeping when a message is received. -->\n\u003Cuses-permission android:name=\"android.permission.WAKE_LOCK\"/>\n","xml","",[56,57,58,67,73,79,85,91,97,103,109,115,121,127,133],"code",{"__ignoreMap":54},[59,60,63],"span",{"class":61,"line":62},"line",1,[59,64,66],{"emptyLinePlaceholder":65},true,"\n",[59,68,70],{"class":61,"line":69},2,[59,71,72],{},"\u003Cpermission\n",[59,74,76],{"class":61,"line":75},3,[59,77,78],{}," android:name=\"com.synyx.cloudmessagetest.permission.C2D_MESSAGE\"\n",[59,80,82],{"class":61,"line":81},4,[59,83,84],{}," android:protectionLevel=\"signature\"/>\n",[59,86,88],{"class":61,"line":87},5,[59,89,90],{},"\u003Cuses-permission android:name=\"com.synyx.cloudmessagetest.permission.C2D_MESSAGE\"/>\n",[59,92,94],{"class":61,"line":93},6,[59,95,96],{}," \u003C!-- App receives GCM messages. -->\n",[59,98,100],{"class":61,"line":99},7,[59,101,102],{},"\u003Cuses-permission android:name=\"com.google.android.c2dm.permission.RECEIVE\"/>\n",[59,104,106],{"class":61,"line":105},8,[59,107,108],{}," \u003C!-- GCM connects to Google Services. -->\n",[59,110,112],{"class":61,"line":111},9,[59,113,114],{},"\u003Cuses-permission android:name=\"android.permission.INTERNET\"/>\n",[59,116,118],{"class":61,"line":117},10,[59,119,120],{}," \u003C!-- GCM requires a Google account. -->\n",[59,122,124],{"class":61,"line":123},11,[59,125,126],{},"\u003Cuses-permission android:name=\"android.permission.GET_ACCOUNTS\"/>\n",[59,128,130],{"class":61,"line":129},12,[59,131,132],{}," \u003C!-- Keeps the processor from sleeping when a message is received. -->\n",[59,134,136],{"class":61,"line":135},13,[59,137,138],{},"\u003Cuses-permission android:name=\"android.permission.WAKE_LOCK\"/>\n",[18,140,141],{},"And declare a GCM broadcast receiver within the application tag:",[49,143,145],{"className":51,"code":144,"language":53,"meta":54,"style":54},"\n\u003Creceiver\n android:name=\"com.google.android.gcm.GCMBroadcastReceiver\"\n android:permission=\"com.google.android.c2dm.permission.SEND\">\n \u003Cintent-filter>\n \u003Caction android:name=\"com.google.android.c2dm.intent.RECEIVE\"/>\n \u003Caction android:name=\"com.google.android.c2dm.intent.REGISTRATION\"/>\n \u003Ccategory android:name=\"com.synyx.cloudmessagetest\"/>\n \u003C/intent-filter>\n\u003C/receiver>\n\u003Cservice android:name=\".GCMIntentService\"/>\n",[56,146,147,151,156,161,166,171,176,181,186,191,196],{"__ignoreMap":54},[59,148,149],{"class":61,"line":62},[59,150,66],{"emptyLinePlaceholder":65},[59,152,153],{"class":61,"line":69},[59,154,155],{},"\u003Creceiver\n",[59,157,158],{"class":61,"line":75},[59,159,160],{}," android:name=\"com.google.android.gcm.GCMBroadcastReceiver\"\n",[59,162,163],{"class":61,"line":81},[59,164,165],{}," android:permission=\"com.google.android.c2dm.permission.SEND\">\n",[59,167,168],{"class":61,"line":87},[59,169,170],{}," \u003Cintent-filter>\n",[59,172,173],{"class":61,"line":93},[59,174,175],{}," \u003Caction android:name=\"com.google.android.c2dm.intent.RECEIVE\"/>\n",[59,177,178],{"class":61,"line":99},[59,179,180],{}," \u003Caction android:name=\"com.google.android.c2dm.intent.REGISTRATION\"/>\n",[59,182,183],{"class":61,"line":105},[59,184,185],{}," \u003Ccategory android:name=\"com.synyx.cloudmessagetest\"/>\n",[59,187,188],{"class":61,"line":111},[59,189,190],{}," \u003C/intent-filter>\n",[59,192,193],{"class":61,"line":117},[59,194,195],{},"\u003C/receiver>\n",[59,197,198],{"class":61,"line":123},[59,199,200],{},"\u003Cservice android:name=\".GCMIntentService\"/>\n",[18,202,203],{},"The GCMIntentService has to be created by us. And that is what we’ll do now. First off, the GCMIntentService has to\nextend the class GCMBaseIntentService:",[49,205,209],{"className":206,"code":207,"language":208,"meta":54,"style":54},"language-java shiki shiki-themes github-light github-dark","public class GCMIntentService extends GCMBaseIntentService {\n","java",[56,210,211],{"__ignoreMap":54},[59,212,213],{"class":61,"line":62},[59,214,207],{},[18,216,217],{},"Now implement all the necessary methods. The only method we will use for this little test is onMessage(). We want to\nquickly see if we get a message for this app, so that we can confirm that it works. So we just create a notification\nwith the Notification Builder.",[18,219,220],{},"Because we are on an older minimum version of Android, we need to add the support library to have access to the\nNotification Builder. Add it by right clicking the project -> Android tools -> Add Support Library.",[18,222,223],{},"First in the onMessage() method, we need to get access to the Main Thread of our App.",[49,225,227],{"className":206,"code":226,"language":208,"meta":54,"style":54},"Handler h = new Handler(Looper.getMainLooper());\nh.post(new Runnable() {\n public void run() {\n }\n}\n",[56,228,229,234,239,244,249],{"__ignoreMap":54},[59,230,231],{"class":61,"line":62},[59,232,233],{},"Handler h = new Handler(Looper.getMainLooper());\n",[59,235,236],{"class":61,"line":69},[59,237,238],{},"h.post(new Runnable() {\n",[59,240,241],{"class":61,"line":75},[59,242,243],{}," public void run() {\n",[59,245,246],{"class":61,"line":81},[59,247,248],{}," }\n",[59,250,251],{"class":61,"line":87},[59,252,253],{},"}\n",[18,255,256],{},"In the run() method, we get us an Intent from our MainActivity",[49,258,260],{"className":206,"code":259,"language":208,"meta":54,"style":54},"Intent notificationIntent = new Intent(context, CloudMessageTestActivity.class);\n",[56,261,262],{"__ignoreMap":54},[59,263,264],{"class":61,"line":62},[59,265,259],{},[18,267,268],{},"And then wrap it with a PendingIntent for the NotificationBuilder",[49,270,272],{"className":206,"code":271,"language":208,"meta":54,"style":54},"PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,\n notificationIntent, 0);\n",[56,273,274,279],{"__ignoreMap":54},[59,275,276],{"class":61,"line":62},[59,277,278],{},"PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,\n",[59,280,281],{"class":61,"line":69},[59,282,283],{}," notificationIntent, 0);\n",[18,285,286],{},"Finally, use the NotificationBuilder to create and send the notification",[49,288,290],{"className":206,"code":289,"language":208,"meta":54,"style":54},"NotificationCompat.Builder builder = new NotificationCompat.Builder(\n context);\nbuilder.setContentIntent(pendingIntent);\nbuilder.setAutoCancel(true);\nbuilder.setSmallIcon(R.drawable.ic_launcher);\n//this is added on the server side\nString text = intent.getStringExtra(\"text\");\nbuilder.setContentText(text);\nbuilder.setContentTitle(\"New message from the cloud!\");\nNotification noti = builder.build();\nNotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);\n//just set the mId to 1, because we don't care about it in this case\nmNotificationManager.notify(1, noti);\n",[56,291,292,297,302,307,312,317,322,327,332,337,342,347,352],{"__ignoreMap":54},[59,293,294],{"class":61,"line":62},[59,295,296],{},"NotificationCompat.Builder builder = new NotificationCompat.Builder(\n",[59,298,299],{"class":61,"line":69},[59,300,301],{}," context);\n",[59,303,304],{"class":61,"line":75},[59,305,306],{},"builder.setContentIntent(pendingIntent);\n",[59,308,309],{"class":61,"line":81},[59,310,311],{},"builder.setAutoCancel(true);\n",[59,313,314],{"class":61,"line":87},[59,315,316],{},"builder.setSmallIcon(R.drawable.ic_launcher);\n",[59,318,319],{"class":61,"line":93},[59,320,321],{},"//this is added on the server side\n",[59,323,324],{"class":61,"line":99},[59,325,326],{},"String text = intent.getStringExtra(\"text\");\n",[59,328,329],{"class":61,"line":105},[59,330,331],{},"builder.setContentText(text);\n",[59,333,334],{"class":61,"line":111},[59,335,336],{},"builder.setContentTitle(\"New message from the cloud!\");\n",[59,338,339],{"class":61,"line":117},[59,340,341],{},"Notification noti = builder.build();\n",[59,343,344],{"class":61,"line":123},[59,345,346],{},"NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);\n",[59,348,349],{"class":61,"line":129},[59,350,351],{},"//just set the mId to 1, because we don't care about it in this case\n",[59,353,354],{"class":61,"line":135},[59,355,356],{},"mNotificationManager.notify(1, noti);\n",[18,358,359],{},"That’ it with the GCMIntentService.",[18,361,362],{},"Now we let the app register itself with GCM in our MainActivity, which is fairly easy:",[49,364,366],{"className":206,"code":365,"language":208,"meta":54,"style":54},"//set your senderId from the API here!\n private static final String SENDER_ID = \"1234567890\";\n@Override\nprotected void onCreate(Bundle savedInstanceState) {\n GCMRegistrar.checkDevice(this);\n GCMRegistrar.checkManifest(this);\n final String regId = GCMRegistrar.getRegistrationId(this);\n // if we don't have a regId yet, register at gcm\n if (regId.equals(\"\")) {\n GCMRegistrar.register(this, SENDER_ID);\n Toast.makeText(getApplicationContext(), \"Registered GCM!\", Toast.LENGTH_LONG).show();\n // just log the registrationId for this test case.\n Log.i(this.getClass().getName(), \"id: \" + GCMRegistrar.getRegistrationId(this));\n } else {\n Log.i(this.getClass().getName(), \"Already registered\");\n Toast.makeText(getApplicationContext(), \"Already registered at GCM!\", Toast.LENGTH_LONG).show();\n Log.i(this.getClass().getName(), \"id: \" + GCMRegistrar.getRegistrationId(this));\n }\n}\n",[56,367,368,373,378,383,388,393,398,403,408,413,418,423,428,433,439,445,451,456,462],{"__ignoreMap":54},[59,369,370],{"class":61,"line":62},[59,371,372],{},"//set your senderId from the API here!\n",[59,374,375],{"class":61,"line":69},[59,376,377],{}," private static final String SENDER_ID = \"1234567890\";\n",[59,379,380],{"class":61,"line":75},[59,381,382],{},"@Override\n",[59,384,385],{"class":61,"line":81},[59,386,387],{},"protected void onCreate(Bundle savedInstanceState) {\n",[59,389,390],{"class":61,"line":87},[59,391,392],{}," GCMRegistrar.checkDevice(this);\n",[59,394,395],{"class":61,"line":93},[59,396,397],{}," GCMRegistrar.checkManifest(this);\n",[59,399,400],{"class":61,"line":99},[59,401,402],{}," final String regId = GCMRegistrar.getRegistrationId(this);\n",[59,404,405],{"class":61,"line":105},[59,406,407],{}," // if we don't have a regId yet, register at gcm\n",[59,409,410],{"class":61,"line":111},[59,411,412],{}," if (regId.equals(\"\")) {\n",[59,414,415],{"class":61,"line":117},[59,416,417],{}," GCMRegistrar.register(this, SENDER_ID);\n",[59,419,420],{"class":61,"line":123},[59,421,422],{}," Toast.makeText(getApplicationContext(), \"Registered GCM!\", Toast.LENGTH_LONG).show();\n",[59,424,425],{"class":61,"line":129},[59,426,427],{}," // just log the registrationId for this test case.\n",[59,429,430],{"class":61,"line":135},[59,431,432],{}," Log.i(this.getClass().getName(), \"id: \" + GCMRegistrar.getRegistrationId(this));\n",[59,434,436],{"class":61,"line":435},14,[59,437,438],{}," } else {\n",[59,440,442],{"class":61,"line":441},15,[59,443,444],{}," Log.i(this.getClass().getName(), \"Already registered\");\n",[59,446,448],{"class":61,"line":447},16,[59,449,450],{}," Toast.makeText(getApplicationContext(), \"Already registered at GCM!\", Toast.LENGTH_LONG).show();\n",[59,452,454],{"class":61,"line":453},17,[59,455,432],{},[59,457,459],{"class":61,"line":458},18,[59,460,461],{}," }\n",[59,463,465],{"class":61,"line":464},19,[59,466,253],{},[18,468,469],{},"Don’t forget to replace the SENDER_ID with yours!",[18,471,472],{},"I haven’t implemented a way to let the server know the registrationId, because reading it from the log seemed sufficient\nfor me in this case.",[18,474,475],{},"With this, we finished our small app and can begin implementing the server part.",[38,477,479],{"id":478},"the-web-application","The Web Application",[18,481,482],{},"For the Web Application, I created a maven web project with spring-webmvc and named it ‘GCMTestServer’. I’ll leave out\nthe config stuff for now, as everyone can use his/her favorite stack for this. The full sources with the configs are\nattached at the end of the blogpost.",[18,484,485,486,490],{},"Instead of just copying the GCM server library into the project, I searched a bit and found someone, who created a\nrepository for\nit. (",[25,487,488],{"href":488,"rel":489},"https://github.com/slorber/gcm-server-repository",[29],")",[18,492,493],{},"We start with creating the Sender class, which isn’t that hard either.",[49,495,497],{"className":206,"code":496,"language":208,"meta":54,"style":54},"public class GCMSender {\n public String apiKey = null;\n public GCMSender(String apiKey) {\n this.apiKey = apiKey;\n }\n public String send(String text, String id) throws IOException {\n Sender sender = new Sender(apiKey);\n Builder builder = new Message.Builder();\n builder.addData(\"text\", text);\n Result result = sender.send(builder.build(), id, 5);\n if (result.getMessageId() != null) {\n String canonicalRegId = result.getCanonicalRegistrationId();\n if (canonicalRegId != null) {\n // same device has more than on registration ID: update database\n return \"same device has more than on registration ID: update database\";\n }\n } else {\n String error = result.getErrorCodeName();\n if (error.equals(Constants.ERROR_NOT_REGISTERED)) {\n // application has been removed from device - unregister database\n return \"application has been removed from device - unregister database\";\n }\n }\n return null;\n }\n}\n",[56,498,499,504,509,514,519,524,529,534,539,544,549,554,559,564,569,574,579,584,589,594,600,606,611,616,622,627],{"__ignoreMap":54},[59,500,501],{"class":61,"line":62},[59,502,503],{},"public class GCMSender {\n",[59,505,506],{"class":61,"line":69},[59,507,508],{}," public String apiKey = null;\n",[59,510,511],{"class":61,"line":75},[59,512,513],{}," public GCMSender(String apiKey) {\n",[59,515,516],{"class":61,"line":81},[59,517,518],{}," this.apiKey = apiKey;\n",[59,520,521],{"class":61,"line":87},[59,522,523],{}," }\n",[59,525,526],{"class":61,"line":93},[59,527,528],{}," public String send(String text, String id) throws IOException {\n",[59,530,531],{"class":61,"line":99},[59,532,533],{}," Sender sender = new Sender(apiKey);\n",[59,535,536],{"class":61,"line":105},[59,537,538],{}," Builder builder = new Message.Builder();\n",[59,540,541],{"class":61,"line":111},[59,542,543],{}," builder.addData(\"text\", text);\n",[59,545,546],{"class":61,"line":117},[59,547,548],{}," Result result = sender.send(builder.build(), id, 5);\n",[59,550,551],{"class":61,"line":123},[59,552,553],{}," if (result.getMessageId() != null) {\n",[59,555,556],{"class":61,"line":129},[59,557,558],{}," String canonicalRegId = result.getCanonicalRegistrationId();\n",[59,560,561],{"class":61,"line":135},[59,562,563],{}," if (canonicalRegId != null) {\n",[59,565,566],{"class":61,"line":435},[59,567,568],{}," // same device has more than on registration ID: update database\n",[59,570,571],{"class":61,"line":441},[59,572,573],{}," return \"same device has more than on registration ID: update database\";\n",[59,575,576],{"class":61,"line":447},[59,577,578],{}," }\n",[59,580,581],{"class":61,"line":453},[59,582,583],{}," } else {\n",[59,585,586],{"class":61,"line":458},[59,587,588],{}," String error = result.getErrorCodeName();\n",[59,590,591],{"class":61,"line":464},[59,592,593],{}," if (error.equals(Constants.ERROR_NOT_REGISTERED)) {\n",[59,595,597],{"class":61,"line":596},20,[59,598,599],{}," // application has been removed from device - unregister database\n",[59,601,603],{"class":61,"line":602},21,[59,604,605],{}," return \"application has been removed from device - unregister database\";\n",[59,607,609],{"class":61,"line":608},22,[59,610,578],{},[59,612,614],{"class":61,"line":613},23,[59,615,461],{},[59,617,619],{"class":61,"line":618},24,[59,620,621],{}," return null;\n",[59,623,625],{"class":61,"line":624},25,[59,626,523],{},[59,628,630],{"class":61,"line":629},26,[59,631,253],{},[18,633,634],{},"To send messages from the server, I created a small jsp page where I can enter the text and the RegistrationId of the\nuser to send the message to:",[49,636,640],{"className":637,"code":638,"language":639,"meta":54,"style":54},"language-html shiki shiki-themes github-light github-dark","\u003C%@ taglib prefix=\"c\" uri=\"http://java.sun.com/jsp/jstl/core\" %> \u003C%@page\ncontentType=\"text/html\" pageEncoding=\"UTF-8\"%>\n\u003C!DOCTYPE html>\n\u003Chtml>\n \u003Chead>\n \u003Cmeta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n \u003Clink\n rel=\"stylesheet\"\n type=\"text/css\"\n href=\"/GCMTestServer/frontend_resources/style.css\"\n media=\"screen\"\n />\n \u003Ctitle>GCM Sender\u003C/title>\n \u003C/head>\n \u003Cbody>\n \u003Ch1>GCM Sender\u003C/h1>\n \u003Cc:if test=\"${success == true}\">\n \u003Cdiv class=\"success\">sending successful!\u003C/div>\n \u003C/c:if>\n \u003Cc:if test=\"${error == true}\">\n \u003Cdiv class=\"error\">\n Error at sending!\n \u003Cp>${errormessage}\u003C/p>\n \u003C/div>\n \u003C/c:if>\n \u003Cform method=\"POST\">\n \u003Clabel for=\"text\">Text\u003C/label\n >\u003Cinput name=\"text\" id=\"text\" type=\"text\" />\u003Cbr />\n \u003Clabel for=\"id\">Registration-Id\u003C/label\n >\u003Cinput name=\"id\" id=\"id\" type=\"text\" />\u003Cbr />\n \u003Cinput type=\"submit\" />\n \u003C/form>\n \u003C/body>\n\u003C/html>\n","html",[56,641,642,657,662,678,686,696,725,732,742,752,762,772,777,791,800,809,821,838,861,870,885,900,905,919,928,936,953,975,1013,1032,1063,1079,1088,1097],{"__ignoreMap":54},[59,643,644,648,652,654],{"class":61,"line":62},[59,645,647],{"class":646},"s7hpK","\u003C",[59,649,651],{"class":650},"sVt8B","%@ taglib prefix=\"c\" uri=\"http://java.sun.com/jsp/jstl/core\" %> ",[59,653,647],{"class":646},[59,655,656],{"class":650},"%@page\n",[59,658,659],{"class":61,"line":69},[59,660,661],{"class":650},"contentType=\"text/html\" pageEncoding=\"UTF-8\"%>\n",[59,663,664,667,671,675],{"class":61,"line":75},[59,665,666],{"class":650},"\u003C!",[59,668,670],{"class":669},"s9eBZ","DOCTYPE",[59,672,674],{"class":673},"sScJk"," html",[59,676,677],{"class":650},">\n",[59,679,680,682,684],{"class":61,"line":81},[59,681,647],{"class":650},[59,683,639],{"class":669},[59,685,677],{"class":650},[59,687,688,691,694],{"class":61,"line":87},[59,689,690],{"class":650}," \u003C",[59,692,693],{"class":669},"head",[59,695,677],{"class":650},[59,697,698,701,704,707,710,714,717,719,722],{"class":61,"line":93},[59,699,700],{"class":650}," \u003C",[59,702,703],{"class":669},"meta",[59,705,706],{"class":673}," http-equiv",[59,708,709],{"class":650},"=",[59,711,713],{"class":712},"sZZnC","\"Content-Type\"",[59,715,716],{"class":673}," content",[59,718,709],{"class":650},[59,720,721],{"class":712},"\"text/html; charset=UTF-8\"",[59,723,724],{"class":650}," />\n",[59,726,727,729],{"class":61,"line":99},[59,728,700],{"class":650},[59,730,731],{"class":669},"link\n",[59,733,734,737,739],{"class":61,"line":105},[59,735,736],{"class":673}," rel",[59,738,709],{"class":650},[59,740,741],{"class":712},"\"stylesheet\"\n",[59,743,744,747,749],{"class":61,"line":111},[59,745,746],{"class":673}," type",[59,748,709],{"class":650},[59,750,751],{"class":712},"\"text/css\"\n",[59,753,754,757,759],{"class":61,"line":117},[59,755,756],{"class":673}," href",[59,758,709],{"class":650},[59,760,761],{"class":712},"\"/GCMTestServer/frontend_resources/style.css\"\n",[59,763,764,767,769],{"class":61,"line":123},[59,765,766],{"class":673}," media",[59,768,709],{"class":650},[59,770,771],{"class":712},"\"screen\"\n",[59,773,774],{"class":61,"line":129},[59,775,776],{"class":650}," />\n",[59,778,779,781,784,787,789],{"class":61,"line":135},[59,780,700],{"class":650},[59,782,783],{"class":669},"title",[59,785,786],{"class":650},">GCM Sender\u003C/",[59,788,783],{"class":669},[59,790,677],{"class":650},[59,792,793,796,798],{"class":61,"line":435},[59,794,795],{"class":650}," \u003C/",[59,797,693],{"class":669},[59,799,677],{"class":650},[59,801,802,804,807],{"class":61,"line":441},[59,803,690],{"class":650},[59,805,806],{"class":669},"body",[59,808,677],{"class":650},[59,810,811,813,815,817,819],{"class":61,"line":447},[59,812,700],{"class":650},[59,814,14],{"class":669},[59,816,786],{"class":650},[59,818,14],{"class":669},[59,820,677],{"class":650},[59,822,823,825,828,831,833,836],{"class":61,"line":453},[59,824,700],{"class":650},[59,826,827],{"class":646},"c:if",[59,829,830],{"class":673}," test",[59,832,709],{"class":650},[59,834,835],{"class":712},"\"${success == true}\"",[59,837,677],{"class":650},[59,839,840,843,846,849,851,854,857,859],{"class":61,"line":458},[59,841,842],{"class":650}," \u003C",[59,844,845],{"class":669},"div",[59,847,848],{"class":673}," class",[59,850,709],{"class":650},[59,852,853],{"class":712},"\"success\"",[59,855,856],{"class":650},">sending successful!\u003C/",[59,858,845],{"class":669},[59,860,677],{"class":650},[59,862,863,866,868],{"class":61,"line":464},[59,864,865],{"class":650}," \u003C/",[59,867,827],{"class":646},[59,869,677],{"class":650},[59,871,872,874,876,878,880,883],{"class":61,"line":596},[59,873,700],{"class":650},[59,875,827],{"class":646},[59,877,830],{"class":673},[59,879,709],{"class":650},[59,881,882],{"class":712},"\"${error == true}\"",[59,884,677],{"class":650},[59,886,887,889,891,893,895,898],{"class":61,"line":602},[59,888,842],{"class":650},[59,890,845],{"class":669},[59,892,848],{"class":673},[59,894,709],{"class":650},[59,896,897],{"class":712},"\"error\"",[59,899,677],{"class":650},[59,901,902],{"class":61,"line":608},[59,903,904],{"class":650}," Error at sending!\n",[59,906,907,910,912,915,917],{"class":61,"line":613},[59,908,909],{"class":650}," \u003C",[59,911,18],{"class":669},[59,913,914],{"class":650},">${errormessage}\u003C/",[59,916,18],{"class":669},[59,918,677],{"class":650},[59,920,921,924,926],{"class":61,"line":618},[59,922,923],{"class":650}," \u003C/",[59,925,845],{"class":669},[59,927,677],{"class":650},[59,929,930,932,934],{"class":61,"line":624},[59,931,865],{"class":650},[59,933,827],{"class":646},[59,935,677],{"class":650},[59,937,938,940,943,946,948,951],{"class":61,"line":629},[59,939,700],{"class":650},[59,941,942],{"class":669},"form",[59,944,945],{"class":673}," method",[59,947,709],{"class":650},[59,949,950],{"class":712},"\"POST\"",[59,952,677],{"class":650},[59,954,956,958,961,964,966,969,972],{"class":61,"line":955},27,[59,957,842],{"class":650},[59,959,960],{"class":669},"label",[59,962,963],{"class":673}," for",[59,965,709],{"class":650},[59,967,968],{"class":712},"\"text\"",[59,970,971],{"class":650},">Text\u003C/",[59,973,974],{"class":669},"label\n",[59,976,978,981,984,987,989,991,994,996,998,1001,1003,1005,1008,1011],{"class":61,"line":977},28,[59,979,980],{"class":650}," >\u003C",[59,982,983],{"class":669},"input",[59,985,986],{"class":673}," name",[59,988,709],{"class":650},[59,990,968],{"class":712},[59,992,993],{"class":673}," id",[59,995,709],{"class":650},[59,997,968],{"class":712},[59,999,1000],{"class":673}," type",[59,1002,709],{"class":650},[59,1004,968],{"class":712},[59,1006,1007],{"class":650}," />\u003C",[59,1009,1010],{"class":669},"br",[59,1012,724],{"class":650},[59,1014,1016,1018,1020,1022,1024,1027,1030],{"class":61,"line":1015},29,[59,1017,842],{"class":650},[59,1019,960],{"class":669},[59,1021,963],{"class":673},[59,1023,709],{"class":650},[59,1025,1026],{"class":712},"\"id\"",[59,1028,1029],{"class":650},">Registration-Id\u003C/",[59,1031,974],{"class":669},[59,1033,1035,1037,1039,1041,1043,1045,1047,1049,1051,1053,1055,1057,1059,1061],{"class":61,"line":1034},30,[59,1036,980],{"class":650},[59,1038,983],{"class":669},[59,1040,986],{"class":673},[59,1042,709],{"class":650},[59,1044,1026],{"class":712},[59,1046,993],{"class":673},[59,1048,709],{"class":650},[59,1050,1026],{"class":712},[59,1052,1000],{"class":673},[59,1054,709],{"class":650},[59,1056,968],{"class":712},[59,1058,1007],{"class":650},[59,1060,1010],{"class":669},[59,1062,724],{"class":650},[59,1064,1066,1068,1070,1072,1074,1077],{"class":61,"line":1065},31,[59,1067,842],{"class":650},[59,1069,983],{"class":669},[59,1071,1000],{"class":673},[59,1073,709],{"class":650},[59,1075,1076],{"class":712},"\"submit\"",[59,1078,724],{"class":650},[59,1080,1082,1084,1086],{"class":61,"line":1081},32,[59,1083,865],{"class":650},[59,1085,942],{"class":669},[59,1087,677],{"class":650},[59,1089,1091,1093,1095],{"class":61,"line":1090},33,[59,1092,795],{"class":650},[59,1094,806],{"class":669},[59,1096,677],{"class":650},[59,1098,1100,1103,1105],{"class":61,"line":1099},34,[59,1101,1102],{"class":650},"\u003C/",[59,1104,639],{"class":669},[59,1106,677],{"class":650},[18,1108,1109],{},"In the corresponding Controller to process the request, send the message:",[49,1111,1113],{"className":206,"code":1112,"language":208,"meta":54,"style":54}," @RequestMapping(value = \"send\", method = RequestMethod.POST)\n public String send(Model model,\n @RequestParam(\"text\") String text,\n @RequestParam(\"id\") String id) {\n String error = null;\n try {\n error = gcmSender.send(text, id);\n } catch (IOException ex) {\n model.addAttribute(\"error\", true);\n model.addAttribute(\"errormessage\", ex.getMessage());\n }\n if (error == null) {\n model.addAttribute(\"success\", true);\n } else {\n model.addAttribute(\"error\", true);\n model.addAttribute(\"errormessage\", error);\n }\n return \"sender\";\n }\n",[56,1114,1115,1120,1125,1130,1135,1140,1145,1150,1155,1160,1165,1170,1175,1180,1185,1189,1194,1198,1203],{"__ignoreMap":54},[59,1116,1117],{"class":61,"line":62},[59,1118,1119],{}," @RequestMapping(value = \"send\", method = RequestMethod.POST)\n",[59,1121,1122],{"class":61,"line":69},[59,1123,1124],{}," public String send(Model model,\n",[59,1126,1127],{"class":61,"line":75},[59,1128,1129],{}," @RequestParam(\"text\") String text,\n",[59,1131,1132],{"class":61,"line":81},[59,1133,1134],{}," @RequestParam(\"id\") String id) {\n",[59,1136,1137],{"class":61,"line":87},[59,1138,1139],{}," String error = null;\n",[59,1141,1142],{"class":61,"line":93},[59,1143,1144],{}," try {\n",[59,1146,1147],{"class":61,"line":99},[59,1148,1149],{}," error = gcmSender.send(text, id);\n",[59,1151,1152],{"class":61,"line":105},[59,1153,1154],{}," } catch (IOException ex) {\n",[59,1156,1157],{"class":61,"line":111},[59,1158,1159],{}," model.addAttribute(\"error\", true);\n",[59,1161,1162],{"class":61,"line":117},[59,1163,1164],{}," model.addAttribute(\"errormessage\", ex.getMessage());\n",[59,1166,1167],{"class":61,"line":123},[59,1168,1169],{}," }\n",[59,1171,1172],{"class":61,"line":129},[59,1173,1174],{}," if (error == null) {\n",[59,1176,1177],{"class":61,"line":135},[59,1178,1179],{}," model.addAttribute(\"success\", true);\n",[59,1181,1182],{"class":61,"line":435},[59,1183,1184],{}," } else {\n",[59,1186,1187],{"class":61,"line":441},[59,1188,1159],{},[59,1190,1191],{"class":61,"line":447},[59,1192,1193],{}," model.addAttribute(\"errormessage\", error);\n",[59,1195,1196],{"class":61,"line":453},[59,1197,1169],{},[59,1199,1200],{"class":61,"line":458},[59,1201,1202],{}," return \"sender\";\n",[59,1204,1205],{"class":61,"line":464},[59,1206,248],{},[18,1208,1209],{},"Now we are ready to test it!",[18,1211,1212],{},"Start the app, copy the RegistrationId from the Logs, start the Server, enter the RegistrationId and a small text, and\nthere you go:",[18,1214,1215],{},[1216,1217],"img",{"alt":1218,"src":1219},"\"notification\"","https://media.synyx.de/uploads//2012/12/notification-300x221.jpg",[18,1221,1222],{},"To get a better understanding, you can also read the rest of the starting guide and the other documentation.",[18,1224,1225],{},"All together, it’s really easy to use the GCM libraries and the messages are beeing sent to the user very fast (around\none second for me). I haven’t tried to use it in a greater context with more users yet, but I don’t think google will\nfail on this behalf 😛",[18,1227,1228,1229],{},"As promised, here are the full sources:",[25,1230,1233],{"href":1231,"rel":1232},"https://media.synyx.de/uploads//2012/12/CloudMessageTest.zip",[29],"CloudMessageTest",[1235,1236,1237],"style",{},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .s7hpK, html code.shiki .s7hpK{--shiki-default:#B31D28;--shiki-default-font-style:italic;--shiki-dark:#FDAEB7;--shiki-dark-font-style:italic}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .s9eBZ, html code.shiki .s9eBZ{--shiki-default:#22863A;--shiki-dark:#85E89D}html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}",{"title":54,"searchDepth":69,"depth":69,"links":1239},[1240,1241],{"id":40,"depth":69,"text":41},{"id":478,"depth":69,"text":479},[1243,1244],"mobile-blog","tutorial","2013-01-08T08:21:24","md","https://synyx.de/blog/a-small-look-into-google-cloud-messages/",{},"/blog/a-small-look-into-google-cloud-messages",{"title":7,"description":20},"blog/a-small-look-into-google-cloud-messages",[1253,1254,1255,1256,1257,1258,1259],"android","cloud","gcm","google-cloud","messages","messaging","push-notification","Within the scope of some Android R&D I took a look at Google’s Cloud Message Service, GCM. Well, the starter guide at http://developer.android.com/google/gcm/gs.html is almost all you need to get started,…","Zo3lVe4ZoQawpHyu6_t-mMTQUwODaiJpqsdkWTxts5M",[1263,1266,1269,1272,1275,1278,1281,1284,1287,1290,1293,1296,1299,1302,1305,1308,1311,1314,1317,1320,1323,1326,1328,1331,1334,1337,1340,1342,1345,1348,1351,1354,1357,1360,1363,1366,1369,1372,1375,1378,1381,1384,1387,1390,1393,1396,1399,1402,1405,1408,1411,1414,1417,1420,1423,1426,1429,1432,1435,1438,1441,1444,1447,1449,1452,1455,1458,1461,1464,1467,1470,1473,1476,1479,1482,1485,1488,1491,1494,1497,1500,1503,1506,1509,1512,1515,1518,1521,1524,1527,1530,1533,1536,1539,1542,1545,1548,1551,1554,1556,1559,1562,1565,1568,1570,1573,1576,1579,1582,1585,1588,1591,1594,1597,1600,1603,1606,1609,1612,1615,1618,1621,1624,1627,1630,1633,1636,1639,1642,1645,1647,1650,1653,1656,1659,1662,1665,1668,1671,1674,1677,1680],{"slug":1264,"name":1265},"abel","Jennifer Abel",{"slug":1267,"name":1268},"allmendinger","Otto Allmendinger",{"slug":1270,"name":1271},"antony","Ben Antony",{"slug":1273,"name":1274},"arrasz","Joachim Arrasz",{"slug":1276,"name":1277},"bauer","David Bauer",{"slug":1279,"name":1280},"bechtold","Janine Bechtold",{"slug":1282,"name":1283},"boersig","Jasmin Börsig",{"slug":1285,"name":1286},"buch","Fabian Buch",{"slug":1288,"name":1289},"buchloh","Aljona Buchloh",{"slug":1291,"name":1292},"burgard","Julia Burgard",{"slug":1294,"name":1295},"caspar-schwedes","Caspar Schwedes",{"slug":1297,"name":1298},"christina-schmitt","Christina Schmitt",{"slug":1300,"name":1301},"clausen","Michael Clausen",{"slug":1303,"name":1304},"contargo_poetzsch","Thomas Pötzsch",{"slug":1306,"name":1307},"damrath","Sebastian Damrath",{"slug":1309,"name":1310},"daniel","Markus Daniel",{"slug":1312,"name":1313},"dasch","Julia Dasch",{"slug":1315,"name":1316},"denman","Joffrey Denman",{"slug":1318,"name":1319},"dfuchs","Daniel Fuchs",{"slug":1321,"name":1322},"dobler","Max Dobler",{"slug":1324,"name":1325},"dobriakov","Vladimir Dobriakov",{"slug":1327,"name":1327},"dreiqbik",{"slug":1329,"name":1330},"dschaefer","Denise Schäfer",{"slug":1332,"name":1333},"dschneider","Dominik Schneider",{"slug":1335,"name":1336},"duerlich","Isabell Duerlich",{"slug":1338,"name":1339},"dutkowski","Bernd Dutkowski",{"slug":1341,"name":1341},"eifler",{"slug":1343,"name":1344},"essig","Tim Essig",{"slug":1346,"name":1347},"ferstl","Maximilian Ferstl",{"slug":1349,"name":1350},"fey","Prisca Fey",{"slug":1352,"name":1353},"frank","Leonard Frank",{"slug":1355,"name":1356},"franke","Arnold Franke",{"slug":1358,"name":1359},"frischer","Nicolette Rudmann",{"slug":1361,"name":1362},"fuchs","Petra Fuchs",{"slug":1364,"name":1365},"gari","Sarah Gari",{"slug":1367,"name":1368},"gast","Gast",{"slug":1370,"name":1371},"graf","Johannes Graf",{"slug":1373,"name":1374},"grammlich","Daniela Grammlich",{"slug":1376,"name":1377},"guthardt","Sabrina Guthardt",{"slug":1379,"name":1380},"haeussler","Johannes Häussler",{"slug":1382,"name":1383},"hammann","Daniel Hammann",{"slug":1385,"name":1386},"heetel","Julian Heetel",{"slug":1388,"name":1389},"heft","Florian Heft",{"slug":1391,"name":1392},"heib","Sebastian Heib",{"slug":1394,"name":1395},"heisler","Ida Heisler",{"slug":1397,"name":1398},"helm","Patrick Helm",{"slug":1400,"name":1401},"herbold","Michael Herbold",{"slug":1403,"name":1404},"hofmann","Peter Hofmann",{"slug":1406,"name":1407},"hopf","Florian Hopf",{"slug":1409,"name":1410},"jaud","Alina Jaud",{"slug":1412,"name":1413},"jayasinghe","Robin De Silva Jayasinghe",{"slug":1415,"name":1416},"jbuch","Jonathan Buch",{"slug":1418,"name":1419},"junghanss","Gitta Junghanß",{"slug":1421,"name":1422},"kadyietska","Khrystyna Kadyietska",{"slug":1424,"name":1425},"kannegiesser","Marc Kannegiesser",{"slug":1427,"name":1428},"karoly","Robert Károly",{"slug":1430,"name":1431},"karrasz","Katja Arrasz-Schepanski",{"slug":1433,"name":1434},"kaufmann","Florian Kaufmann",{"slug":1436,"name":1437},"kesler","Mike Kesler",{"slug":1439,"name":1440},"kirchgaessner","Bettina Kirchgäßner",{"slug":1442,"name":1443},"klem","Yannic Klem",{"slug":1445,"name":1446},"klenk","Timo Klenk",{"slug":9,"name":1448},"Tobias Knell",{"slug":1450,"name":1451},"knoll","Anna-Lena Knoll",{"slug":1453,"name":1454},"knorre","Matthias Knorre",{"slug":1456,"name":1457},"koenig","Melanie König",{"slug":1459,"name":1460},"kraft","Thomas Kraft",{"slug":1462,"name":1463},"krupicka","Florian Krupicka",{"slug":1465,"name":1466},"kuehn","Christian Kühn",{"slug":1468,"name":1469},"lange","Christian Lange",{"slug":1471,"name":1472},"larrasz","Luca Arrasz",{"slug":1474,"name":1475},"leist","Sascha Leist",{"slug":1477,"name":1478},"lihs","Michael Lihs",{"slug":1480,"name":1481},"linsin","David Linsin",{"slug":1483,"name":1484},"maniyar","Christian Maniyar",{"slug":1486,"name":1487},"martin","Björnie",{"slug":1489,"name":1490},"martin-koch","Martin Koch",{"slug":1492,"name":1493},"matt","Tobias Matt",{"slug":1495,"name":1496},"mennerich","Christian Mennerich",{"slug":1498,"name":1499},"menz","Alexander Menz",{"slug":1501,"name":1502},"meseck","Frederick Meseck",{"slug":1504,"name":1505},"messner","Oliver Messner",{"slug":1507,"name":1508},"michael-ploed","Michael Plöd",{"slug":1510,"name":1511},"mies","Marius Mies",{"slug":1513,"name":1514},"mihai","Alina Mihai",{"slug":1516,"name":1517},"moeller","Jörg Möller",{"slug":1519,"name":1520},"mohr","Rebecca Mohr",{"slug":1522,"name":1523},"moretti","David Moretti",{"slug":1525,"name":1526},"mueller","Sven Müller",{"slug":1528,"name":1529},"muessig","Alexander Müssig",{"slug":1531,"name":1532},"neupokoev","Grigory Neupokoev",{"slug":1534,"name":1535},"nussbaecher","Carmen Nussbächer",{"slug":1537,"name":1538},"ochs","Pascal Ochs",{"slug":1540,"name":1541},"oelhoff","Jan Oelhoff",{"slug":1543,"name":1544},"oengel","Yasin Öngel",{"slug":1546,"name":1547},"oezsoy","Enis Özsoy",{"slug":1549,"name":1550},"posch","Maya Posch",{"slug":1552,"name":1553},"ralfmueller","Ralf Müller",{"slug":1555,"name":1555},"redakteur",{"slug":1557,"name":1558},"reich","Michael Reich",{"slug":1560,"name":1561},"reinhard","Karl-Ludwig Reinhard",{"slug":1563,"name":1564},"rmueller","Rebecca Müller",{"slug":1566,"name":1567},"rosum","Jan Rosum",{"slug":1569,"name":1569},"rueckert",{"slug":1571,"name":1572},"ruessel","Sascha Rüssel",{"slug":1574,"name":1575},"sauter","Moritz Sauter",{"slug":1577,"name":1578},"schaefer","Julian Schäfer",{"slug":1580,"name":1581},"scherer","Petra Scherer",{"slug":1583,"name":1584},"schlicht","Anne Schlicht",{"slug":1586,"name":1587},"schmidt","Jürgen Schmidt",{"slug":1589,"name":1590},"schneider","Tobias Schneider",{"slug":1592,"name":1593},"seber","Benjamin Seber",{"slug":1595,"name":1596},"sommer","Marc Sommer",{"slug":1598,"name":1599},"speaker-fels","Jakob Fels",{"slug":1601,"name":1602},"speaker-gierke","Oliver Gierke",{"slug":1604,"name":1605},"speaker-krupa","Malte Krupa",{"slug":1607,"name":1608},"speaker-mader","Jochen Mader",{"slug":1610,"name":1611},"speaker-meusel","Tim Meusel",{"slug":1613,"name":1614},"speaker-milke","Oliver Milke",{"slug":1616,"name":1617},"speaker-paluch","Mark Paluch",{"slug":1619,"name":1620},"speaker-schad","Jörg Schad",{"slug":1622,"name":1623},"speaker-schalanda","Jochen Schalanda",{"slug":1625,"name":1626},"speaker-schauder","Jens Schauder",{"slug":1628,"name":1629},"speaker-unterstein","Johannes Unterstein",{"slug":1631,"name":1632},"speaker-wolff","Eberhard Wolff",{"slug":1634,"name":1635},"speaker-zoerner","Stefan Zörner",{"slug":1637,"name":1638},"stefan-belger","Stefan Belger",{"slug":1640,"name":1641},"steinegger","Roland Steinegger",{"slug":1643,"name":1644},"stern","sternchen synyx",{"slug":1646,"name":1646},"synyx",{"slug":1648,"name":1649},"szulc","Mateusz Szulc",{"slug":1651,"name":1652},"tamara","Tamara Tunczinger",{"slug":1654,"name":1655},"theuer","Tobias Theuer",{"slug":1657,"name":1658},"thieme","Sandra Thieme",{"slug":1660,"name":1661},"thies-clasen","Marudor",{"slug":1663,"name":1664},"toernstroem","Olle Törnström",{"slug":1666,"name":1667},"ullinger","Max Ullinger",{"slug":1669,"name":1670},"ulrich","Stephan Ulrich",{"slug":1672,"name":1673},"wagner","Stefan Wagner",{"slug":1675,"name":1676},"weigel","Andreas Weigel",{"slug":1678,"name":1679},"werner","Fabian Werner",{"slug":1681,"name":1682},"wolke","Sören Wolke",["Reactive",1684],{"$scookieConsent":1685,"$ssite-config":1687},{"functional":1686,"analytics":1686},false,{"_priority":1688,"env":1692,"name":1693,"url":1694},{"name":1689,"env":1690,"url":1691},-10,-15,0,"production","nuxt-app","https://synyx.de",["Set"],["ShallowReactive",1697],{"category-gcm":-1,"authors":-1},"/blog/tags/gcm"]