如何发出长时间通知?

问题描述 投票:0回答:2

我正在为要使用特定人员的特定设备做申请...,我想在其中输入长文字...可以吗?我确信可以以某种方式将文本放在状态栏的前面...

我不确定是否可以像我在图片上一样长时间发出通知...。

所以有人可以帮助我在状态栏前面加上该文本吗?谢谢

enter image description here

android android-studio notifications statusbar
2个回答
0
投票

您可以使用此通知样式

NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(this)
                    .setSmallIcon(R.drawable.ic_notification)
                    .setContentTitle(title)
                    .setStyle(new NotificationCompat.BigTextStyle()
                                      .bigText(message))
                    .setContentText(message)                                            
                    .setDefaults(NotificationCompat.DEFAULT_SOUND)
                    .setContentIntent(contentIntent)
                    .setAutoCancel(true);

mNotificationManager.notify(requestID, mBuilder.build());

但是在状态栏中取决于设备,某些设备会自动从通知中获取文本。


0
投票

我希望您正在谈论通知状态栏图标。

从Android 5.0开始,“通知图标必须完全为白色”。

Notification notification = new NotificationCompat.Builder(this);
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    notification.setSmallIcon(R.drawable.icon_transperent);
    notification.setColor(getResources().getColor(R.color.notification_color));
} else { 
    notification.setSmallIcon(R.drawable.icon);
}

您可以通过按照this文档创建透明图标。

如果要显示冗长的通知图标,那是不可能的,Android系统会将其修剪为预定义的大小,因此您的图标可能会被裁剪。

预定义的大小是

MDPI - 24 x 24  (drawable-mdpi)
HDPI - 36 x 36  (drawable-hdpi)
XHDPI - 48 x 48  (drawable-xhdpi)
XXHDPI - 72 x 72  (drawable-xxhdpi)
XXXHDPI - 96 x 96  (drawable-xxxhdpi)
© www.soinside.com 2019 - 2024. All rights reserved.