通知图标未在Android 9上显示

时间:2019-10-14 09:10:54

标签: android android-9.0-pie

我在使用Android 9的通知时遇到问题,在Android 9中未显示通知图标。我已使用以下代码显示带有通知的图标。

.
.
.
OracleConnection test = new OracleConnection();
.
.
.

        using (OracleConnection test = new OracleConnection("Data Source=; User ID=; Password=")) // <-- SQLconnection here
        {

            test.Open(); // <-- Only Open connection

            using (OracleDataReader reader = cmd.ExecuteReader())
            {
.
.
.
            }
         }

2 个答案:

答案 0 :(得分:1)

最后我找到了解决方案(使用 Android 9

步骤1 :您的图片将是白色且背景透明。

步骤2:,您已根据应用图标设置了背景颜色。

if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

           notificationBuilder.setSmallIcon(R.mipmap.ic_appoint);// this is the white image with transparent background
            notificationBuilder.setColor(getResources().getColor(R.color.colorGreen));
        } else {
            notificationBuilder.setSmallIcon(R.drawable.ic_notify); // this is normal image 
        }

答案 1 :(得分:0)

Implementation of `Notification Builder` for below and above Lollipop OS version would be:


NotificationCompat.Builder notificationBuilder = new 
NotificationCompat.Builder(this);

notificationBuilder.setSmallIcon(getNotificationIcon(notificationBuilder));

private int getNotificationIcon(NotificationCompat.Builder 
notificationBuilder) {

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
         int color = 0x008000;
         notificationBuilder.setColor(color);
         return R.drawable.app_icon_lolipop_above;

 } 
 return R.drawable.app_icon_lolipop_below;
 }