Android的通知按钮没有显示出来按钮、通知、Android

2023-09-03 22:20:13 作者:念旧回不到曾经

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

This is my code to set up a notification with buttons.

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 我在一个片段设置此通知。我究竟做错了什么?谢谢!

Notification is showing up but buttons don't. My device has Android 4.1.1 I set up this notification in a Fragment. What am I doing wrong? Thanks!

推荐答案

让我来告诉你这是非常尴尬的。 如果你有什么在你正在进行的通知,你不会看到这些按钮。 通常情况下它发生的时候,你必须通过USB连接手机到电脑。 希望这能解决你的问题。

Let me tell you something which is really awkward. If you have anything in your Ongoing Notification, You wont see the buttons. Typically it happens when you have phone connected to PC via USB. Hope this solves your problem