API级别26上的通知图标

时间:2018-02-20 16:56:03

标签: android push-notification

当应用关闭时,我不明白android api 26用于推送通知的图标。当我收到推送通知时,它始终是droid的默认图标。

我从ressources中删除所有默认图标,设置android:roundIcon="@drawable/ic_launcher"(ic_launcher是png)

编辑: 我的问题是,当系统托盘显示通知https://firebase.google.com/docs/cloud-messaging/android/receive

3 个答案:

答案 0 :(得分:0)

您在通知对象中设置的图标是显示

notification.setSmallIcon(R.drawable.icon);

例如

NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    Intent resultIntent = new Intent(getApplicationContext(), MainActivity.class);
    resultIntent.putExtras(bundle);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
            resultIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
    Notification notification;
    Uri sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notificationsound);
 notification = new Notification.Builder(this)
                .setSmallIcon(R.drawable.lg_logo)
                .setContentTitle(title)
                .setStyle(new Notification.BigTextStyle().bigText(msg))
                .setAutoCancel(true)
                .setContentText(msg)
                .setContentIntent(contentIntent)
                .setSound(sound)
                .build();
    notificationManager.notify(0, notification);

答案 1 :(得分:0)

用户notification.setSmallIcon(R.drawable.icon);在使用图片时也设置小图标,但不要大于250px X 250px。

答案 2 :(得分:0)

将以下代码放入您Manifest.xml

           <meta-data
            android:name="com.google.firebase.messaging.default_notification_icon"
            android:resource="@drawable/ic_notification" />
           <meta-data
            android:name="com.google.firebase.messaging.default_notification_color"
            android:resource="@color/colorAccent" />

此外,请确保您生成的图标符合Google提供的指南。 Here is official guidelines