我正在为我的大学制作应用程序,现在我想在其中发送有关事件的消息/信息。我如何向他们发送信息。我试过firebase但是,它一直工作直到推送通知。我想如果有人点击通知它应该打开一个包含整个消息/信息的新活动,任何代码参考将非常有帮助。
使用有效负载将信息放入您的通知中。这可能是一个事件ID。您的通知文本也由您的服务器设置。
由于有效负载,您的应用客户端知道通知收到了什么事件ID(通知打开时)。只需向您的数据库询问客户收到的事件ID中的信息,即可获得所需的一切。
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替换为在单击通知时要重定向的任何活动。
如果我误解了您的要求,请随时发表评论。