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

Adi*_*esh 26 notifications android android-notifications android-notification-bar android-studio

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

在此输入图像描述

    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());
}
Run Code Online (Sandbox Code Playgroud)

Man*_*nta 57

在通知构建器中尝试此代码:

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());
Run Code Online (Sandbox Code Playgroud)

设置大图标就可以了.如果您有任何进一步的信息,请在下方评论

  • 在2019年无法使用。帮助大图标仍是带有白色透明小图标的灰色圆圈 (2认同)

Ada*_*dam 53

我知道在这里回答的时间已经很晚了,而且它已经得到了解答,但我来到这里寻找一个使用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" />
Run Code Online (Sandbox Code Playgroud)

  • 你的回答是最有帮助的。谢了哥们。 (4认同)