简体   繁体   English

将发布通知发送到特定的UUID android设备

[英]Send post notification to specific UUID android device

I'm trying to find some ways to send a post notification to specific android device using its UUID , so I will do the following : 我正在尝试找到一些使用其UUID将发布通知发送到特定android设备的方法,因此我将执行以下操作:

1 : login screen on android and then get UUID number from the device 1:在android上登录屏幕,然后从设备获取UUID号

2 : send this UUID to online database linked to userID 2:将此UUID发送到链接到userID的在线数据库

3 : I want to know how to send post notification to a specific UUID which I get from my database ? 3:我想知道如何将发布通知发送到从数据库中获取的特定UUID?

Sending notification to android device using java is very easy. 使用Java向Android设备发送通知非常容易。

If you want to push the notification directly from REST client, then you can refer this 如果要直接从REST客户端推送通知,则可以参考

If you want to send notifications from your java program, then follow these simple steps, 如果您要从Java程序发送通知,请按照以下简单步骤操作,

  • Add gcm-server.jar library file in your application 在您的应用程序中添加gcm-server.jar库文件
  • Create a Sender, that will send the notification 创建一个发件人,它将发送通知

      com.google.android.gcm.server.Sender sender = new Sender("pass your gcm api key here"); 
  • Then create a message object that will contain the data that you want to send 然后创建一个消息对象,其中将包含您要发送的数据

     com.google.android.gcm.server.Message message = new Message.Builder().addData("key","value").build(); 

addData("key","value") in above code will add the key value in json to be send. 上面代码中的addData("key","value")将在json中添加要发送的键值。

  • Then you can choose any of send method provided in Sender class 然后,您可以选择Sender类中提供的任何send方法

      com.google.android.gcm.server.Result result = sender.send(message, device_token, no of retries); 

There are total four version of send method available. 共有四种版本的send方法可用。 You can find more detail about Sender class here 您可以在此处找到有关Sender类的更多详细信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM