简体   繁体   English

Android小通知图标未在5.1中显示(LOLLIPOP)

[英]Android small notification icon not showing in 5.1 (LOLLIPOP)

I have implemented Push notification and it it's working fine but when I receive the notification small notification icon is not showing on LOLLIPOP and Large icon is showing fine and on the status bar when I receive the notification a square box is showing on on LOLLIPOP i will post my code , my small notification icon image and my code, please any one guide me . 我已经实现了推送通知,它工作正常,但是当我收到通知时, 小通知图标未 在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) {
        }
    }

[![enter image description here][1]][1] [![在此处输入图片描述] [1]] [1] 在此处输入图片说明

As noted in Android 5.0 Behavior Changes of the Android Developers site under Notifications: 如“通知”下Android开发者网站的Android 5.0行为更改中所述:

Notifications are drawn with dark text atop white (or very light) backgrounds to match the new material design widgets. 通知在白色(或非常浅)的背景上以深色文字绘制,以匹配新的材质设计小部件。 Make sure that all your notifications look right with the new color scheme. 确保使用新的配色方案,所有通知均正确显示。 If your notifications look wrong, fix them: 如果您的通知看起来不正确,请修复它们:

Use setColor() to set an accent color in a circle behind your icon image. 使用setColor()在图标图像后面的圆圈中设置强调色。 Update or remove assets that involve color. 更新或删除涉及颜色的资产。 The system ignores all non-alpha channels in action icons and in the main notification icon. 系统将忽略操作图标和主通知图标中的所有非Alpha通道。 You should assume that these icons will be alpha-only. 您应该假定这些图标将仅是Alpha。 The system draws notification icons in white and action icons in dark gray. 系统以白色绘制通知图标,以深灰色绘制动作图标。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM