我想创建一个应用程序,将 show internet speed as notification in status bar
问题是,当我创建通知时,它只显示图标,但我认为这不是方式(if you think there is a way using this then how ?
)我使用这个代码片段来显示通知,但如果我想得到别人得到的结果,如你可以看到也在屏幕截图中的变化做 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());
通知中的文字每秒都在变化,这不是假的。此法 但不准确,因为它与通知图标重叠。Any help
将被赞赏的感谢提前。
你可以在位图上画出你想显示的文字,然后将其设置为通知的图标。
NotificationCompat.Builder notification = new NotificationCompat.Builder(this, CHANNEL_ID_2);
notification.setSmallIcon(Icon.createWithBitmap(getBitmapIcon()))
实现 getBitmapIcon()
并返回你要显示的位图图标。