gpt4 book ai didi

java - 如何动态更改状态栏中的文本

转载 作者:行者123 更新时间:2023-12-01 16:30:13 25 4
gpt4 key购买 nike

我想创建一个应用程序 show internet speed as notification in status bar问题是,当我创建通知时,它只显示图标,但我认为这不是方式( if you think there is a way using this then how ? ),我使用此代码 fragment 来显示通知,但如果我想要其他人得到的结果,该怎么做?另请参阅 leftmost side 中的屏幕截图:

Intent intent = new Intent(this, MainActivity.class);
PendingIntent contenIntent = PendingIntent.getActivity(this,
0, intent, 0);

NotificationCompat.Builder notification = new NotificationCompat.Builder(this, CHANNEL_ID_2)
.setLargeIcon(getBitmapFromString("22", 20, this))
.setContentTitle("Title")
.setContentText("Description")
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setContentIntent(contenIntent)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setTicker("23")
.setSmallIcon(android.R.drawable.screen_background_light_transparent)
.setOnlyAlertOnce(true);

NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(1, notification.build());

status bar screen shot

通知中的文本每秒都会发生变化,而且它不是假的。我已经尝试过this solution但不准确,因为它与通知图标重叠。 Any help提前致谢。

最佳答案

您可以绘制要在位图上显示的文本,然后将其设置为通知的图标。

NotificationCompat.Builder notification = new NotificationCompat.Builder(this, CHANNEL_ID_2);

notification.setSmallIcon(Icon.createWithBitmap(getBitmapIcon()))

实现getBitmapIcon()并返回您想要显示的位图图标。

关于java - 如何动态更改状态栏中的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62059848/

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