【问题标题】:Android small notification icon not showing in 5.1 (LOLLIPOP)Android 小通知图标未在 5.1 中显示(棒棒糖)
【发布时间】:2016-01-29 11:14:32
【问题描述】:

我已经实现了推送通知,它工作正常,但是当我收到通知时 小通知图标没有显示 在 LOLLIPOP大图标显示正常 当我收到通知时,状态栏上会显示一个方框,在 LOLLIPOP 上会显示我的代码、我的小通知图标图像和我的代码,请任何人指导我。

public void sendNotification(Context context,String message, String action) {
        try {
            int icon = R.drawable.notilogoboss;
            String title = context.getString(R.string.app_name);

            Intent intent = new Intent(context, MainActivity.class);
            intent.putExtra("message", message);
            intent.putExtra("action", action);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP| Intent.FLAG_ACTIVITY_SINGLE_TOP);

            PendingIntent pendingIntent = PendingIntent.getActivity(context,0,intent,PendingIntent.FLAG_UPDATE_CURRENT);

            Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

            NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
                    .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.logoboss))
                    .setSmallIcon(icon)
                    .setContentTitle(title)
                    .setWhen(System.currentTimeMillis())
                    .setContentText(message)
                    .setAutoCancel(true)
                    .setSound(defaultSoundUri)
                    .setDefaults(Notification.DEFAULT_ALL) // requires VIBRATE permission
                    .setStyle(new NotificationCompat.BigTextStyle().bigText(message))
                    .setContentIntent(pendingIntent);

            NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
            int notId = UUID.randomUUID().hashCode();
            notificationManager.notify(notId, notificationBuilder.build());

        } catch (Exception e) {
        }
    }

[![在此处输入图像描述][1]][1]

【问题讨论】:

  • 您需要使用平面图标。透明背景的白色
  • 是扁平的方形图标正在工作,请帮助我
  • 我正在使用 40x40 图标背景填充仍然得到白色方块只有棒棒糖之前的默认图标即将到来但在 5.0 之后唯一的问题请帮助我并提供一些有用的代码

标签: java android push-notification android-5.0-lollipop android-notifications


【解决方案1】:

如 Android 开发者网站通知下的 Android 5.0 行为更改中所述:

通知在白色(或非常浅的)背景上使用深色文本绘制,以匹配新的材料设计小部件。确保您的所有通知都与新的配色方案相匹配。如果您的通知看起来有问题,请修复它们:

使用 setColor() 在图标图像后面的圆圈中设置强调色。更新或删除涉及颜色的资产。系统会忽略操作图标和主通知图标中的所有非 Alpha 通道。您应该假设这些图标仅是 Alpha 版。系统以白色绘制通知图标,以深灰色绘制操作图标。

http://developer.android.com/about/versions/android-5.0-changes.html.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-05
    • 2020-10-06
    • 2015-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多