我想通过通知发送信息

问题描述:

我正在为我的大学开发一个应用程序,现在我想发送关于事件的消息/信息。我如何发送信息给他们。我尝试了firebase,但它一直在推送通知。我想如果有人点击通知它应该打开一个新的活动与整个消息/信息任何代码参考将是非常有益的。我想通过通知发送信息

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

} 

当上述函数被调用时,会生成通知,并且通过单击通知将用户重定向到特定的活动。在意图中,将your_acitivity.class替换为单击通知时要重定向的任何活动。

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

+0

Bilal,我的信息将会在200字左右。是否有可能与Firebase? –

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

感谢有效载荷,您的应用程序客户端知道通知(通知打开时)时收到了什么事件ID。只需向客户数据库询问客户收到的事件ID中的信息,即可获得所需的全部信息。