Nexus中未显示Android通知应用图标

时间:2017-05-03 09:37:34

标签: android push-notification

我需要在通知栏中获取下面红色的app图标。但仍显示第一个AppName通知

enter image description here

我在firebaseMessageingService类

中使用了这样的代码
 NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setContentTitle(getString(R.string.app_name))
            .setContentText(messageBody)
            .setStyle(new NotificationCompat.BigTextStyle().bigText(messageBody))
            .setAutoCancel(true)
            .setVibrate(pattern)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);
NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify(LocalRepository.getNotificationId(), notificationBuilder.build());

我也在我的gradle中更改了targetSdkVersion 20。 提前致谢

2 个答案:

答案 0 :(得分:0)

如果您想支持Lollipop材质图标,请为Lollipop制作透明图标。

Notification Builder可以通过以下方法实现,以下Lollipop OS版本将是:

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
  if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        mBuilder.setSmallIcon(R.drawable.icon_transperent);
  } else { 
         mBuilder.setSmallIcon(R.drawable.icon);
  } 

答案 1 :(得分:-2)

enter image description here

检查这一点我需要像红色通知一样 但是我的表现仍然如此。

 if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        notificationBuilder.setSmallIcon(R.drawable.ic_notification)
                .setStyle(new NotificationCompat.BigTextStyle().bigText(messageBody))
                .setAutoCancel(true)
                .setVibrate(pattern)
                .setSound(defaultSoundUri)
                .setContentIntent(pendingIntent);
    } else {
        notificationBuilder.setSmallIcon(R.mipmap.ic_launcher)
                .setContentText(messageBody)
                .setStyle(new NotificationCompat.BigTextStyle().bigText(messageBody))
                .setAutoCancel(true)
                .setVibrate(pattern)
                .setSound(defaultSoundUri)
                .setContentIntent(pendingIntent);
    }


compileSdkVersion 25
buildToolsVersion "25.0.0"
defaultConfig {
    minSdkVersion 16
    targetSdkVersion 20
    versionCode 9
    versionName "2.0.1"