显示白色在棒棒糖和上面设备的通知象 [英] Notification Icon showing white on lollipop and above devices

查看:114
本文介绍了显示白色在棒棒糖和上面设备的通知象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用FCM进行推送通知,下面是我生成通知的代码:

I am using FCM for push notification and below is my code for generating a notification:

 Intent intent = new Intent(this, HomeActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
        PendingIntent.FLAG_ONE_SHOT);
Notification.Builder notification;
if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
    notification = new Notification.Builder(this);
} else {
    notification = new Notification.Builder(this);
    notification.setColor(getResources().getColor(R.color.sysTransparent));
}

notification.setSmallIcon(R.mipmap.ic_launcher)
        .setContentTitle("Notification Title")
        .setContentText("This is notification body")
        .setAutoCancel(true)
        .setContentIntent(pendingIntent);

NotificationManager notificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

notificationManager.notify(0, notification.build());

这是输出:

有谁知道如何去除多余的白色?

Does anyone know how to remove the excess white?

推荐答案


尝试这个,它适用于我

try this one, it works for me



protected void displayNotification(Context context, String[] strContent) {
        try {
            int numMessages = 0;

            /* Invoking the default notification service */
            NotificationCompat.Builder  mBuilder = new NotificationCompat.Builder(this);

            mBuilder.setContentTitle("New "+strContent[0].trim());
            mBuilder.setContentText("You've received new "+strContent[0].trim());
            mBuilder.setTicker("New "+strContent[0].trim()+" Alert!");
            mBuilder.setSmallIcon(R.drawable.ic_notif);
            mBuilder.setAutoCancel(true);
            mBuilder.setColor(context.getResources().getColor(R.color.ColorPrimary));
            mBuilder.setVisibility(Notification.VISIBILITY_PUBLIC);
            mBuilder.setDefaults(Notification.DEFAULT_ALL);
            mBuilder.setVibrate(new long[] {1000, 1000, 1000, 1000, 1000});         

            mBuilder.setLights(Color.RED, 3000, 3000);
         mBuilder.setNumber(++numMessages);

        NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();

            String[] events = new String[strContent.length-1];
            for(int i=0; i<strContent.length-1; i++){
                events[i] = new String(strContent[i+1].trim());
            }

            inboxStyle.setBigContentTitle("New "+strContent[0].trim()+" received!");

            for (int i=0; i < events.length; i++) {
                inboxStyle.addLine(events[i]);
            }

            mBuilder.setStyle(inboxStyle);

            /* Creates an explicit intent for an Activity in your app */
            Intent resultIntent = new Intent(this, HomeActivity.class);


            TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
            stackBuilder.addParentStack(HomeActivity.class);

            /* Adds the Intent that starts the Activity to the top of the stack */
            stackBuilder.addNextIntent(resultIntent);
            PendingIntent resultPendingIntent =stackBuilder.getPendingIntent(0,PendingIntent.FLAG_UPDATE_CURRENT);

            mBuilder.setContentIntent(resultPendingIntent);
            NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

            /* notificationID allows you to update the notification later on. */
            mNotificationManager.notify(9999, mBuilder.build());
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }
    }

这篇关于显示白色在棒棒糖和上面设备的通知象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆