Android 通知按钮不显示

新手上路,请多包涵

这是我设置带有按钮的通知的代码。

 Intent receiverIntent = new Intent(ctx, ResponsivePrefsActivity.class);
        PendingIntent pReceiverIntent = PendingIntent.getActivity(ctx, 1, receiverIntent, 0);
        Intent clearIntent = new Intent(ctx, ResponsivePrefsActivity.class);
        clearIntent.setAction("clear");
        PendingIntent pClearIntent = PendingIntent.getActivity(ctx, 1, clearIntent, 0);

        Intent colorsIntent = new Intent(ctx, ResponsivePrefsActivity.class);
        colorsIntent.setAction("colors");
        PendingIntent pColorsIntent = PendingIntent.getActivity(ctx, 1, colorsIntent, 0);

        Intent animationIntent = new Intent(ctx, ResponsivePrefsActivity.class);
        animationIntent.setAction("animation");
        PendingIntent pAnimation = PendingIntent.getActivity(ctx, 1, animationIntent, 0);

        Notification.Builder builder;
        builder = new Notification.Builder(ctx).setSmallIcon(R.drawable.ic_launcher).setAutoCancel(false)
                .setContentTitle("Draw Me: A Live Wallpaper").setContentText("Never get bored again!")
                .setContentIntent(pReceiverIntent).addAction(R.raw.ic_menu_close_clear_cancel, "Clear", pClearIntent)
                .addAction(R.raw.ic_menu_edit, "Colors", pColorsIntent).addAction(R.raw.ic_menu_play_clip, "Animation", pAnimation);
        Notification notification = builder.build();

        NotificationManager notificationManager = (NotificationManager) ctx.getSystemService(Context.NOTIFICATION_SERVICE);

        notificationManager.notify(0, notification);

通知正在显示,但按钮没有。我的设备有 Android 4.1.1 我在片段中设置了这个通知。我究竟做错了什么?谢谢!

原文由 DraganescuValentin 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 728
2 个回答

让我告诉你一件非常尴尬的事。如果您的持续通知中有任何内容,您将看不到按钮。通常,当您通过 USB 将手机连接到 PC 时,就会发生这种情况。希望这能解决你的问题

原文由 CommonMan 发布,翻译遵循 CC BY-SA 3.0 许可协议

只是提醒任何有类似问题的人。根据 Android Notifications Guide ,通知可以以两种样式显示:

  • 普通视图,默认情况下不显示操作按钮(用户必须展开通知才能显示)
  • 大视图,如果通知在通知列表中位于第一个,或者用户展开了通知,则可见。

因此,为了强制通知出现在 Big View 中,我们所要做的就是将它放在通知列表的顶部。这可以通过将 When 属性设置为 0 来完成,这使它成为最旧的通知! (有时我们可能不希望这样)。所以打电话

setWhen(0)

到您的通知,您就完成了。

原文由 paulahniuk 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题