使用操作按钮推送通知不起作用

时间:2017-01-28 06:48:48

标签: android firebase notifications android-notifications

我已经使用fcm进行通知并且它正确显示,但是当我尝试在通知中添加添加按钮时它没有显示。

我的代码

   Intent intent = new Intent(this, MainActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
            PendingIntent.FLAG_ONE_SHOT);

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setContentTitle("New Message From Film")
            .setContentText(messageBody)
            .setAutoCancel(true)
             .addAction(R.drawable.pp, "Accept",pendingIntent) 
            .addAction(R.drawable.pp, "Reject",pendingIntent)  
            .setContentIntent(pendingIntent);
  NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0, notificationBuilder.build());

1 个答案:

答案 0 :(得分:0)

您忘了在最后

中构建使用方法build()

已修改的代码

构建器

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
        .setSmallIcon(R.mipmap.ic_launcher)
        .setContentTitle("New Message From Film")
        .setContentText(messageBody)
        .setAutoCancel(true)
         .addAction(R.drawable.pp, "Accept",pendingIntent) 
        .addAction(R.drawable.pp, "Reject",pendingIntent)  
        .setContentIntent(pendingIntent);

通知

final Notification notification = notificationBuilder.build();
mNotificationManager.notify(notificationId, notification);