简体   繁体   English

如何将推送通知发送到Android中的其他设备?

[英]how to send push Notifications to other device in android?

Using this code, i am able to send a notification to my own device. 使用此代码,我可以将通知发送到我自己的设备。

           Intent intent = new Intent(getApplicationContext(), ContactDonor.class);
            PendingIntent pi = PendingIntent.getActivity(getApplicationContext(), 0, intent, 0);
            //display text
            String body = "Please Click on this to accept!";
            String title = bloodgroup+" Required";
            Notification n = new Notification(R.drawable.ic_launcher, body , System.currentTimeMillis());
            n.setLatestEventInfo(getApplicationContext(), title, body, pi);
            n.defaults = Notification.DEFAULT_ALL;
            nm.notify(uniqueID, n);
            finish();

But now i have a screen where a person's details are displayed like: Name: ... email: ... , and there is a message box and a Request Button , on the click of that button, he should receive a notification with that particular message. 但是现在我有了一个显示人的详细信息的屏幕,例如:姓名:...电子邮件:...,还有一个消息框和一个请求按钮,单击该按钮,他应该会收到一个通知特定消息。 How can this particular thing be done? 怎么做这件事?

It cannot be implemented by using PUSH notifications . 它不能通过使用PUSH notifications来实现。 PUSH notification is useful when there is server-client comm is implemented where server notifies the client about the event that has occurred on server side. 当实现server-client通信时, server通知client有关server端发生的事件时, PUSH notification很有用。

What you are trying to implement indirectly is server-client architecture, where your device will act as server. 您尝试间接实现的是服务器-客户端体系结构,您的设备将在其中充当服务器。 If you mould your current architecture to server-client you will be able to send notification to other device. 如果您将当前架构调整为服务器-客户端,则可以将通知发送到其他设备。 In this case also, you don't need PUSH notifications, it will be a simple server-client communication. 同样,在这种情况下,您也不需要PUSH通知,这将是简单的服务器-客户端通信。

For more info on PUSH please see: http://www.vogella.com/articles/AndroidCloudToDeviceMessaging/article.html#c2dm_sendmessage 有关PUSH的更多信息,请参见: http : //www.vogella.com/articles/AndroidCloudToDeviceMessaging/article.html#c2dm_sendmessage

You can also send SMS, but that will not solve your problem. 您也可以发送短信,但这不能解决您的问题。 According to me, there is no other solution that you can apply to send notification. 据我介绍,您没有其他可用于发送通知的解决方案。

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

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