Android 通知中不显示操作按钮

Android 通知中不显示操作按钮,android,notifications,android-notifications,Android,Notifications,Android Notifications,我想在通知栏中显示操作按钮。通知有效,但我看不到任何按钮。我在网上读过Android开发者文档和不同的例子,但我没有发现我的代码有什么大的不同。我做了如下工作: public void showNotification(Context context) { NotificationManager mNotifyMgr = (NotificationManager); context.getSystemService(Context.NOTIFICATION_SERVIC

我想在通知栏中显示操作按钮。通知有效,但我看不到任何按钮。我在网上读过Android开发者文档和不同的例子,但我没有发现我的代码有什么大的不同。我做了如下工作:

public void showNotification(Context context) {
    NotificationManager mNotifyMgr = (NotificationManager);     
    context.getSystemService(Context.NOTIFICATION_SERVICE);
    NotificationCompat.Builder = new NotificationCompat.Builder(context);

    Intent prevIntent = new Intent(mContext, PlayAudioService.class);
    prevIntent.setAction(ACTION_PREV);
    PendingIntent piPrev = PendingIntent.getService(mContext, 0, prevIntent, 0);

    Intent playIntent = new Intent(mContext, PlayAudioService.class);
    playIntent.setAction(ACTION_PLAY);
    PendingIntent piPlay = PendingIntent.getService(mContext, 0, playIntent, 0);

    Intent nextIntet = new Intent(mContext, PlayAudioService.class);
    nextIntet.setAction(ACTION_NEXT);
    PendingIntent piNext = PendingIntent.getService(mContext, 0, nextIntet, 0);

    mBuilder.setSmallIcon(smallIcon)
                .setContentTitle("Title")
                .setContentText("Text")
                .setTicker("Ticker")
                .setWhen(0)
                //.setStyle(new NotificationCompat.BigTextStyle().bigText(title))
            .addAction (R.drawable.ic_previous, "Prev", piPrev)
                .addAction (R.drawable.ic_play,     "Play", piPlay)
                .addAction (R.drawable.ic_next,     "Next", piNext);

    Intent notifyIntent = new Intent(context, MainActivity.class);
    notifyIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);

    PendingIntent piNotify =
                PendingIntent.getActivity(
                mContext,
                0,
                notifyIntent,
                PendingIntent.FLAG_UPDATE_CURRENT
        );
    mBuilder.setContentIntent(piNotify);
    mNotifyMgr.notify(mNotificationId, mBuilder.build());
}
在活动中:

showNotification(this);
我的Android目标SDK版本15,我正在使用最新版本的支持库v4。我遗漏了什么,没有正确理解


您的答复将不胜感激。

中引入了通知操作

这意味着您应该将目标SDK设置为16或更高

然而,只有Jelly Bean和更高版本可以利用通知操作——请确保在这些平台上测试此功能


NotificationCompat.Builder
负责生成与它所运行的任何API兼容的通知,因此,如果您打算支持冰淇淋三明治或更早的版本,请继续使用它。如果没有,只需使用
Notification.Builder
就足够了(当然,在更改了目标SDK之后)。

中引入了通知操作

这意味着您应该将目标SDK设置为16或更高

然而,只有Jelly Bean和更高版本可以利用通知操作——请确保在这些平台上测试此功能


NotificationCompat.Builder
负责生成与它所运行的任何API兼容的通知,因此,如果您打算支持冰淇淋三明治或更早的版本,请继续使用它。如果没有,只需使用
Notification.Builder
即可(当然,在更改目标SDK之后)。

感谢您的回答,非常有用。我没有看到API是从API 16引入的。谢谢你的回答,非常有用。我没有看到API是从API 16引入的。