\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},{"loc":1249},"blog/a-small-look-into-google-cloud-messages",[1254,1255,1256,1257,1258,1259,1260],"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,…","OAaYVJ_tCf4EjtyhcR8UEkVStNcR69sWPts5WylIFqc",[1264,1267,1270,1273,1276,1279,1282,1285,1288,1291,1294,1297,1300,1303,1306,1309,1312,1315,1318,1321,1324,1327,1329,1332,1335,1338,1341,1343,1346,1349,1352,1355,1358,1361,1364,1367,1370,1373,1376,1379,1382,1385,1388,1391,1394,1397,1400,1403,1406,1409,1412,1415,1418,1421,1424,1427,1430,1433,1436,1439,1442,1445,1448,1450,1453,1456,1459,1462,1465,1468,1471,1474,1477,1480,1483,1486,1489,1492,1495,1498,1501,1504,1507,1510,1513,1516,1519,1522,1525,1528,1531,1534,1537,1540,1543,1546,1549,1552,1555,1557,1560,1563,1566,1569,1571,1574,1577,1580,1583,1586,1589,1592,1595,1598,1601,1604,1607,1610,1613,1616,1619,1622,1625,1628,1631,1634,1637,1640,1643,1646,1648,1651,1654,1657,1660,1663,1666,1669,1672,1675,1678,1681],{"slug":1265,"name":1266},"abel","Jennifer Abel",{"slug":1268,"name":1269},"allmendinger","Otto Allmendinger",{"slug":1271,"name":1272},"antony","Ben Antony",{"slug":1274,"name":1275},"arrasz","Joachim Arrasz",{"slug":1277,"name":1278},"bauer","David Bauer",{"slug":1280,"name":1281},"bechtold","Janine Bechtold",{"slug":1283,"name":1284},"boersig","Jasmin Börsig",{"slug":1286,"name":1287},"buch","Fabian Buch",{"slug":1289,"name":1290},"buchloh","Aljona Buchloh",{"slug":1292,"name":1293},"burgard","Julia Burgard",{"slug":1295,"name":1296},"caspar-schwedes","Caspar Schwedes",{"slug":1298,"name":1299},"christina-schmitt","Christina Schmitt",{"slug":1301,"name":1302},"clausen","Michael Clausen",{"slug":1304,"name":1305},"contargo_poetzsch","Thomas Pötzsch",{"slug":1307,"name":1308},"damrath","Sebastian Damrath",{"slug":1310,"name":1311},"daniel","Markus Daniel",{"slug":1313,"name":1314},"dasch","Julia Dasch",{"slug":1316,"name":1317},"denman","Joffrey Denman",{"slug":1319,"name":1320},"dfuchs","Daniel Fuchs",{"slug":1322,"name":1323},"dobler","Max Dobler",{"slug":1325,"name":1326},"dobriakov","Vladimir Dobriakov",{"slug":1328,"name":1328},"dreiqbik",{"slug":1330,"name":1331},"dschaefer","Denise Schäfer",{"slug":1333,"name":1334},"dschneider","Dominik Schneider",{"slug":1336,"name":1337},"duerlich","Isabell Duerlich",{"slug":1339,"name":1340},"dutkowski","Bernd Dutkowski",{"slug":1342,"name":1342},"eifler",{"slug":1344,"name":1345},"essig","Tim Essig",{"slug":1347,"name":1348},"ferstl","Maximilian Ferstl",{"slug":1350,"name":1351},"fey","Prisca Fey",{"slug":1353,"name":1354},"frank","Leonard Frank",{"slug":1356,"name":1357},"franke","Arnold Franke",{"slug":1359,"name":1360},"frischer","Nicolette Rudmann",{"slug":1362,"name":1363},"fuchs","Petra Fuchs",{"slug":1365,"name":1366},"gari","Sarah Gari",{"slug":1368,"name":1369},"gast","Gast",{"slug":1371,"name":1372},"graf","Johannes Graf",{"slug":1374,"name":1375},"grammlich","Daniela Grammlich",{"slug":1377,"name":1378},"guthardt","Sabrina Guthardt",{"slug":1380,"name":1381},"haeussler","Johannes Häussler",{"slug":1383,"name":1384},"hammann","Daniel Hammann",{"slug":1386,"name":1387},"heetel","Julian Heetel",{"slug":1389,"name":1390},"heft","Florian Heft",{"slug":1392,"name":1393},"heib","Sebastian Heib",{"slug":1395,"name":1396},"heisler","Ida Heisler",{"slug":1398,"name":1399},"helm","Patrick Helm",{"slug":1401,"name":1402},"herbold","Michael Herbold",{"slug":1404,"name":1405},"hofmann","Peter Hofmann",{"slug":1407,"name":1408},"hopf","Florian Hopf",{"slug":1410,"name":1411},"jaud","Alina Jaud",{"slug":1413,"name":1414},"jayasinghe","Robin De Silva Jayasinghe",{"slug":1416,"name":1417},"jbuch","Jonathan Buch",{"slug":1419,"name":1420},"junghanss","Gitta Junghanß",{"slug":1422,"name":1423},"kadyietska","Khrystyna Kadyietska",{"slug":1425,"name":1426},"kannegiesser","Marc Kannegiesser",{"slug":1428,"name":1429},"karoly","Robert Károly",{"slug":1431,"name":1432},"karrasz","Katja Arrasz-Schepanski",{"slug":1434,"name":1435},"kaufmann","Florian Kaufmann",{"slug":1437,"name":1438},"kesler","Mike Kesler",{"slug":1440,"name":1441},"kirchgaessner","Bettina Kirchgäßner",{"slug":1443,"name":1444},"klem","Yannic Klem",{"slug":1446,"name":1447},"klenk","Timo Klenk",{"slug":9,"name":1449},"Tobias Knell",{"slug":1451,"name":1452},"knoll","Anna-Lena Knoll",{"slug":1454,"name":1455},"knorre","Matthias Knorre",{"slug":1457,"name":1458},"koenig","Melanie König",{"slug":1460,"name":1461},"kraft","Thomas Kraft",{"slug":1463,"name":1464},"krupicka","Florian Krupicka",{"slug":1466,"name":1467},"kuehn","Christian Kühn",{"slug":1469,"name":1470},"lange","Christian Lange",{"slug":1472,"name":1473},"larrasz","Luca Arrasz",{"slug":1475,"name":1476},"leist","Sascha Leist",{"slug":1478,"name":1479},"lihs","Michael Lihs",{"slug":1481,"name":1482},"linsin","David Linsin",{"slug":1484,"name":1485},"maniyar","Christian Maniyar",{"slug":1487,"name":1488},"martin","Björnie",{"slug":1490,"name":1491},"martin-koch","Martin Koch",{"slug":1493,"name":1494},"matt","Tobias Matt",{"slug":1496,"name":1497},"mennerich","Christian Mennerich",{"slug":1499,"name":1500},"menz","Alexander Menz",{"slug":1502,"name":1503},"meseck","Frederick Meseck",{"slug":1505,"name":1506},"messner","Oliver Messner",{"slug":1508,"name":1509},"michael-ploed","Michael Plöd",{"slug":1511,"name":1512},"mies","Marius Mies",{"slug":1514,"name":1515},"mihai","Alina Mihai",{"slug":1517,"name":1518},"moeller","Jörg Möller",{"slug":1520,"name":1521},"mohr","Rebecca Mohr",{"slug":1523,"name":1524},"moretti","David Moretti",{"slug":1526,"name":1527},"mueller","Sven Müller",{"slug":1529,"name":1530},"muessig","Alexander Müssig",{"slug":1532,"name":1533},"neupokoev","Grigory Neupokoev",{"slug":1535,"name":1536},"nussbaecher","Carmen Nussbächer",{"slug":1538,"name":1539},"ochs","Pascal Ochs",{"slug":1541,"name":1542},"oelhoff","Jan Oelhoff",{"slug":1544,"name":1545},"oengel","Yasin Öngel",{"slug":1547,"name":1548},"oezsoy","Enis Özsoy",{"slug":1550,"name":1551},"posch","Maya Posch",{"slug":1553,"name":1554},"ralfmueller","Ralf Müller",{"slug":1556,"name":1556},"redakteur",{"slug":1558,"name":1559},"reich","Michael Reich",{"slug":1561,"name":1562},"reinhard","Karl-Ludwig Reinhard",{"slug":1564,"name":1565},"rmueller","Rebecca Müller",{"slug":1567,"name":1568},"rosum","Jan Rosum",{"slug":1570,"name":1570},"rueckert",{"slug":1572,"name":1573},"ruessel","Sascha Rüssel",{"slug":1575,"name":1576},"sauter","Moritz Sauter",{"slug":1578,"name":1579},"schaefer","Julian Schäfer",{"slug":1581,"name":1582},"scherer","Petra Scherer",{"slug":1584,"name":1585},"schlicht","Anne Schlicht",{"slug":1587,"name":1588},"schmidt","Jürgen Schmidt",{"slug":1590,"name":1591},"schneider","Tobias Schneider",{"slug":1593,"name":1594},"seber","Benjamin Seber",{"slug":1596,"name":1597},"sommer","Marc Sommer",{"slug":1599,"name":1600},"speaker-fels","Jakob Fels",{"slug":1602,"name":1603},"speaker-gierke","Oliver Gierke",{"slug":1605,"name":1606},"speaker-krupa","Malte Krupa",{"slug":1608,"name":1609},"speaker-mader","Jochen Mader",{"slug":1611,"name":1612},"speaker-meusel","Tim Meusel",{"slug":1614,"name":1615},"speaker-milke","Oliver Milke",{"slug":1617,"name":1618},"speaker-paluch","Mark Paluch",{"slug":1620,"name":1621},"speaker-schad","Jörg Schad",{"slug":1623,"name":1624},"speaker-schalanda","Jochen Schalanda",{"slug":1626,"name":1627},"speaker-schauder","Jens Schauder",{"slug":1629,"name":1630},"speaker-unterstein","Johannes Unterstein",{"slug":1632,"name":1633},"speaker-wolff","Eberhard Wolff",{"slug":1635,"name":1636},"speaker-zoerner","Stefan Zörner",{"slug":1638,"name":1639},"stefan-belger","Stefan Belger",{"slug":1641,"name":1642},"steinegger","Roland Steinegger",{"slug":1644,"name":1645},"stern","sternchen synyx",{"slug":1647,"name":1647},"synyx",{"slug":1649,"name":1650},"szulc","Mateusz Szulc",{"slug":1652,"name":1653},"tamara","Tamara Tunczinger",{"slug":1655,"name":1656},"theuer","Tobias Theuer",{"slug":1658,"name":1659},"thieme","Sandra Thieme",{"slug":1661,"name":1662},"thies-clasen","Marudor",{"slug":1664,"name":1665},"toernstroem","Olle Törnström",{"slug":1667,"name":1668},"ullinger","Max Ullinger",{"slug":1670,"name":1671},"ulrich","Stephan Ulrich",{"slug":1673,"name":1674},"wagner","Stefan Wagner",{"slug":1676,"name":1677},"weigel","Andreas Weigel",{"slug":1679,"name":1680},"werner","Fabian Werner",{"slug":1682,"name":1683},"wolke","Sören Wolke",["Reactive",1685],{"$scookieConsent":1686,"$ssite-config":1688},{"functional":1687,"analytics":1687},false,{"_priority":1689,"env":1693,"name":1694,"url":1695},{"name":1690,"env":1691,"url":1692},-10,-15,0,"production","nuxt-app","https://synyx.de",["Set"],["ShallowReactive",1698],{"category-messages":-1,"authors":-1},"/blog/tags/messages"]