操作按钮都没有显示通知 [英] Action buttons are not shown in notification

查看:201
本文介绍了操作按钮都没有显示通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要在通知栏显示操作按钮。通知工作,但我看不到任何按钮。我已阅读Android开发者文档,并在互联网上不同的例子,但我找不到我的code任何大的差别。我做了类似以下内容:

I want to display action buttons in notification bar. Notification works but I cannot see any button . I have read Android Developer document and different examples on the Internet but I could not find any big difference with my code. I have done like following:

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

我的Andr​​oid目标SDK版本15和我使用的最新版本的支持库V4的。我在想什么,并没有正确理解?

My Android target SDK version 15 and I am using latest version of support library v4. What am I missing and did not understand properly?

您的答案是AP preciated。

Your answer would be appreciated.

推荐答案

通知操作中的 API 16

这意味着,你应该将目标SDK可以设置为16或以上。

This means that you should be setting your target SDK to 16 or above.

然而,只有果冻豆及以上的可采取行动的通知优势 - 确保测试在这些平台上此功能

However, only Jelly Bean and above can take advantage of the Notification Actions - make sure to test this feature on those platforms.

NotificationCompat.Builder 需要产生与任何API它运行在兼容的通知的照顾,所以继续使用它,如果你将要支持冰淇淋三明治及以上。如果不是,简单地使用 Notification.Builder 就足够了(当然改变的目标SDK后)。

NotificationCompat.Builder takes care of generating a Notification compatible with whatever API it is running on, so keep using it if you are going to be supporting Ice Cream Sandwich and older. If not, simply using Notification.Builder will suffice (after changing the target SDK of course).

这篇关于操作按钮都没有显示通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆