我正在为我的大学制作一个应用程序,现在我想在其中发送关于事件的消息/信息。我如何向他们发送信息。我尝试过firebase,但它只能工作到推送通知。我希望如果有人点击通知,它应该打开一个新的活动与整个消息/信息,任何代码参考将是非常有用的。
发布于 2017-07-03 19:43:26
public void getnotification() {
NotificationManager notificationmgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Intent intent = new Intent(this, your_acitivity.class);
PendingIntent pintent = PendingIntent.getActivities(this, (int) System.currentTimeMillis(), new Intent[]{intent}, PendingIntent.FLAG_UPDATE_CURRENT);
Notification notif = new Notification.Builder(this)
.setSmallIcon(R.drawable.shadow_fiend)
.setContentTitle(notif_title)//Title of the notification
.setContentText(notif_detail)//Description of the notification
.setContentIntent(pintent)
.setAutoCancel(true)
.build();
notificationmgr.notify(0, notif);
}
当调用上述函数时,将生成一个通知,并通过单击该通知将用户重定向到特定的活动。在intent中,将your_acitivity.class替换为您希望在单击通知时重定向的任何活动。
如果我误解了您的要求,请随时发表评论。
发布于 2017-07-03 19:43:57
使用有效负载将信息放入通知中。这可能是一个事件id。您的通知文本也由您的服务器设置。
多亏了有效负载,您的应用程序客户端才知道通知接收到的事件ID (当通知打开时)。只需向您的数据库查询从客户端接收到的事件id的信息,您就拥有了所需的所有信息。
https://stackoverflow.com/questions/44884537
复制相似问题