it-swarm.dev

如何在通知抽屉中将应用程序图标设置为通知图标

如图所示...
我正在收到通知图标(左侧为红色)。
但是我需要显示黑色箭头所示的应用程序图标

enter image description here

    public void notify(View view){
    notification.setSmallIcon(R.drawable.ic_stat_name);
    notification.setTicker("Welcome to ****");
    notification.setWhen(System.currentTimeMillis());
    notification.setContentTitle("abcd");
    notification.setContentText("abcd");


    Intent intent = new Intent(this, home.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    notification.setContentIntent(pendingIntent);


    NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    nm.notify(uniqueID, notification.build());
}
23
Aditya Suresh

在通知生成器上尝试以下代码:

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context)
                .setSmallIcon(R.mipmap.ic_launcher)
                .setLargeIcon(BitmapFactory.decodeResource(context.getResources(),
                        R.mipmap.ic_launcher))
                .setContentTitle(title)
                .setContentText(message)
                .setAutoCancel(true)
                .setSound(defaultSoundUri)
                .setContentIntent(pendingIntent);

Android.app.NotificationManager notificationManager =
                (Android.app.NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());

Set Large图标可以解决问题。如果您有其他信息,请在下面评论

52
Manikanta

我知道在这里回答它有点晚了,而且已经被回答了,但是我来这里是寻找使用firebase通知的简单解决方案。像我这样来这里访问的人可以通过推荐的简单方法来实现解决方案,即通过将Firebase通知简单地添加到清单中。

参考

<!-- Set custom default icon. This is used when no icon is set for incoming notification messages. -->
<meta-data
    Android:name="com.google.firebase.messaging.default_notification_icon"
    Android:resource="@drawable/ic_stat_ic_notification" />
<!-- Set color used with incoming notification messages. This is used when no color is set for the incoming notification message. -->
<meta-data
    Android:name="com.google.firebase.messaging.default_notification_color"
    Android:resource="@color/colorAccent" />
49
Adam