Java的GCM服务器端实现 [英] GCM server side implementation for java

查看:240
本文介绍了Java的GCM服务器端实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为gcm的服务器端实现一个独立的应用程序,以将通知推送到设备。除了入门页面上的内容外,是否还有其他参考资料可供参考。人们对xmpp进行了说明。我们是否需要使用这个,或者我们可以直接使用gcm服务器端的方法。帮助或者是有其他简单的方法来实现this.I希望我把我的问题妥善。

I need to implement a standalone application for the server side of gcm to push notifications to the device. Is there any reference i could get other than the one on the Getting started page.People say something about xmpp. Do we need to use this or can we directly use the gcm server side methods.Help.Or is there any other easy way to implement this.I hope i put my question properly.

推荐答案

这是用于java的GCM服务器端实现的很好的教程。
URL: java gcm服务器端实现 a>

Here is nice tutorial for GCM server side implementation for java. URL: java gcm server side implementation

示例代码:java gcm服务器端实现`{b / b
$ b

Example code: java gcm server side implementation`{

    new Thread(){

        public void run(){

            try {
                //Please add here your project API key: "Key for browser apps (with referers)".
                //If you added "API key Key for server apps (with IP locking)" or "Key for Android apps (with certificates)" here
                //then you may get error responses.
                Sender sender = new  Sender("AIzaSyB7Ej255tpTaemk_-Ljmn4GcklldT14Hp4");

                // use this to send message with payload data
                Message message = new Message.Builder()
                .collapseKey("message")
                .timeToLive(3)
                .delayWhileIdle(true)
                .addData("message", "Welcome to Push Notifications") //you can get this message on client side app
                .build(); 

                //Use this code to send notification message to a single device
                Result result = sender.send(message,
                        "APA91bEbKqwTbvvRuc24vAYljcrhslOw-jXBqozgH8C2OB3H8R7U00NbIf1xp151ptweX9VkZXyHMik022cNrEETm7eM0Z2JnFksWEw1niJ2sQfU3BjQGiGMq8KsaQ7E0jpz8YKJNbzkTYotLfmertE3K7RsJ1_hAA",
                        1);
                System.out.println("Message Result: "+result.toString()); //Print message result on console

                //Use this code to send notification message to multiple devices
                ArrayList<String> devicesList = new ArrayList<String>();
                //add your devices RegisterationID, one for each device               
                devicesList.add("APA91bEbKqwTbvvRuc24vAYljcrhslOw-jXBqozgH8C2OB3H8R7U00NbIf1xp151ptweX9VkZXyHMik022cNrEETm7eM0Z2JnFksWEw1niJ2sQfU3BjQGiGMq8KsaQ7E0jpz8YKJNbzkTYotLfmertE3K7RsJ1_hAA");   
                devicesList.add("APA91bEVcqKmPnESzgnGpEstHHymcpOwv52THv6u6u2Rl-PaMI4mU3Wkb9bZtuHp4NLs4snBl7aXXVkNn-IPEInGO2jEBnBI_oKEdrEoTo9BpY0i6a0QHeq8LDZd_XRzGRSv_R0rjzzZ1b6jXY60QqAI4P3PL79hMg");   

                //Use this code for multicast messages   
                MulticastResult multicastResult = sender.send(message, devicesList, 0);
                System.out.println("Message Result: "+multicastResult.toString());//Print multicast message result on console

            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }.start();   
}`

这篇关于Java的GCM服务器端实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆