简体   繁体   中英

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 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.

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.

For more info on PUSH please see: 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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