java - Android 小通知图标在 5.1 中不显示(LOLLIPOP)

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

我已经实现了推送通知,它工作正常,但是当我收到通知时小通知图标没有显示在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] enter image description here

最佳答案

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

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

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

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

关于java - Android 小通知图标在 5.1 中不显示(LOLLIPOP),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35083121/

相关文章:

java - 从Java中的谷歌地图API解析Json数组

java - MySQL 查询获取球体中的行(X、Y、Z 坐标)?

android - 如何创建类似画廊的 View

ajax - 如何让所有连接的浏览器重新加载由服务器端事件启动

azure - 使用 Azure 通知中心进行徽章管理

java - 简单的电影院预订系统

java - 将实例变量初始化为 null、 ""或 0

java - 致命异常 : java. lang.RuntimeException - 由 java.lang.IllegalStateException 引起。应为 BEGIN_ARRAY,但实际为 BEGIN_OBJECT

android - 相机获取参数失败

android - 如何使用应用程序私有(private)文件夹中的文件设置通知声音?