我想通过通知发送信息

时间:2017-07-03 11:36:03

标签: android mobile push-notification

我正在为我的大学制作一个应用程序,现在我想在其中发送有关事件的消息/信息。我如何向他们发送信息。我试过firebase但是,它一直工作直到推送通知。我想如果有人点击通知,它应该打开一个包含整个消息/信息的新活动,任何代码参考都将非常有用。

2 个答案:

答案 0 :(得分:0)

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替换为在单击通知时要重定向的任何活动。

如果我误解了您的要求,请随意发表评论。

答案 1 :(得分:0)

使用有效负载将信息放入您的通知中。这可能是一个事件ID。您的通知文本也由您的服务器设置。

由于有效负载,您的应用客户端知道通知收到了什么事件ID(通知打开时)。只需向您的数据库询问有关客户收到的事件ID的信息,您就拥有了所需的一切。