Android 通知按钮未显示

标签 android button notifications action

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

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 我在 fragment 中设置了这个通知。我究竟做错了什么?谢谢!

最佳答案

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

关于Android 通知按钮未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18249871/

相关文章:

android - 从 4 升级到 4.1 后启动 android studio 时出错 (MacOS 10.15)

javascript - 组合功能+禁用

wordpress - 如何禁用 Plesk 12.0.18 更新通知(特别是对于 WordPress 和客户)

iphone - MPMediaLibrary DidChangeNotification 调用了两次?

javascript - 部署 Firebase Cloud Function 时出现 "Each then should return a value or throw"错误

android - 如何为整个 Android 系统创建和管理自定义主题?

Android TabLayout PagerAdapter 不显示第一个选项卡 fragment

python - 确定在 Tkinter 中按下了哪个按钮?

android - 加权按钮上的文本不占用与按钮相同的空间

java - 当屏幕上显示 JPanel 时,如何获得通知