gpt4 book ai didi

android - 通知不显示但不会抛出任何错误 [Android]

转载 作者:行者123 更新时间:2023-11-29 20:03:54 25 4
gpt4 key购买 nike

我刚刚更新了我的 android 应用程序中的 ic_launcher(顺便说一句,是在 Android Studio 中制作的)。我正在尝试创建一个测试通知,它曾经有效,但现在无效,我也不知道为什么。

Notification.Builder builder = new Notification.Builder(this);
builder
.setWhen(System.currentTimeMillis())
.setContentTitle("TEST")
.setContentText("Hello! This is a notification test!")
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher));

NotificationManager NoMa = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
NoMa.notify(1, builder.build());

如果我删除 setLargeIcon 行,它甚至不起作用,在我看来这是没有意义的。我不排除我的代码有问题的可能性。谢谢。

最佳答案

如果你想显示任何通知,你必须setSmallIcon()。因此,将您的代码更改为

Notification.Builder builder = new Notification.Builder(this);
builder
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.mipmap.ic_launcher) //Any icon you want
.setContentTitle("TEST")
.setContentText("Hello! This is a notification test!")
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher));

NotificationManager NoMa = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
NoMa.notify(1, builder.build());

关于android - 通知不显示但不会抛出任何错误 [Android],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35900864/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com