2

我正在尝试使用操作按钮实现自定义通知

但是当我尝试实现这一点时,不会出现操作按钮和应用程序名称。

我的实现:

    RemoteViews remoteViews = new 
    RemoteViews(getPackageName(),R.layout.emotions_notification);
    Intent receiver = new Intent();
    receiver.setAction("Action");
    PendingIntent pendingIntentYes = PendingIntent.getBroadcast(this, 12345, receiver, PendingIntent.FLAG_UPDATE_CURRENT);


    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, "feelBetter.emotions")

      .setContent(remoteViews)
      .setContentIntent(pendingIntent)
      .setSmallIcon(R.drawable.ic_status_bar)

      .setPriority(NotificationCompat.PRIORITY_DEFAULT)
      .setColor(Color.parseColor("#322176"))
      .setLights(Color.parseColor("#322176"), 1000, 1000)
      .addAction(R.drawable.common_google_signin_btn_icon_dark_normal, "Action", pendingIntentYes)
      .setSound(uri)
      .setAutoCancel(true);

    notificationManager = NotificationManagerCompat.from(this);

    // notificationId is a unique int for each notification that you must define
    notificationManager.notify(id, mBuilder.build());

如何实施?

4

1 回答 1

3

尝试这个

// Get the layouts to use in the custom notification
RemoteViews notificationLayout = new RemoteViews(getPackageName(), R.layout.notification_small);
RemoteViews notificationLayoutExpanded = new RemoteViews(getPackageName(), R.layout.notification_large);

// Apply the layouts to the notification
Notification customNotification = new NotificationCompat.Builder(context, CHANNEL_ID)
        .setSmallIcon(R.drawable.notification_icon)
        .setStyle(new NotificationCompat.DecoratedCustomViewStyle())
        .setCustomContentView(notificationLayout)
        .setCustomBigContentView(notificationLayoutExpanded)
        .build();
于 2018-07-13T04:10:01.933 回答