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

标签 android android-notifications android-notification-bar

使用此代码,我可以向我自己的设备发送通知。

           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();

但现在我有一个屏幕,上面显示了一个人的详细信息,例如: 姓名: ... 电子邮件: ... ,并且有一个消息框和一个请求按钮,单击该按钮时,他应该会收到包含该特定消息的通知。如何才能完成这件特别的事情?

最佳答案

它不能通过使用PUSH 通知 来实现。 PUSH notificationserver-client comm 实现时很有用,其中 server 通知 client 有关事件发生在服务器端。

您尝试间接实现的是服务器-客户端架构,您的设备将在其中充当服务器。如果您将当前架构塑造为服务器-客户端,您将能够向其他设备发送通知。在这种情况下,您也不需要推送通知,这将是一个简单的服务器-客户端通信。

有关 PUSH 的更多信息,请参阅:http://www.vogella.com/articles/AndroidCloudToDeviceMessaging/article.html#c2dm_sendmessage

您也可以发送短信,但这并不能解决您的问题。根据我的说法,您没有其他解决方案可以申请发送通知。

关于android - 如何将推送通知发送到android中的其他设备?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11098404/

相关文章:

java - Android Studio 外部 jar 错误

android - 提供的依赖只能是jar

安卓输入法 : how to show a pop-up dialog?

java - Android 小通知图标在 5.1 中不显示(LOLLIPOP)

android - ListenableWorker 不移除通知图标

android - 为什么 Android Lollipop 中使用 Notification.Builder.setSmallIcon 设置的图标显示为白色方 block ?

android - 在通知图标中添加数字

java - Mac OS Yosemite 上缺少 JDK 1.8 虚拟机

Android 在 GCM 上注册设备导致 SERVICE_NOT_AVAILABLE