【问题标题】:Not able to change Icon in android studio using setsmallIcon无法使用 setsmallIcon 在 android studio 中更改图标
【发布时间】:2021-01-16 10:07:57
【问题描述】:

无法使用 NotificationCompat.Builder 中的 setsmallIcon 更改 android studio 中的图标

下面是我在 android 10 上尝试和测试的代码


public class MyFirebaseMessagingService extends FirebaseMessagingService {
    @Override
    public void onMessageReceived(@NonNull RemoteMessage remoteMessage) {
        super.onMessageReceived(remoteMessage);
        getFirebaseMessage(remoteMessage.getNotification().getTitle(), remoteMessage.getNotification().getBody());
    }

    public void getFirebaseMessage(String title, String msg){

        NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "myFirebaseChannel")
                .setLargeIcon(BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher))
                .setSmallIcon(R.mipmap.ic_launcher)
                .setContentTitle(title)
                .setContentText(msg)
                .setAutoCancel(true);


        NotificationManagerCompat managerCompat = NotificationManagerCompat.from(this);

        managerCompat.notify(101, builder.build());
    }
}

【问题讨论】:

  • 通知中是否出现白色方形图标?
  • @rahat 是的......有点......我得到一个白色圆圈
  • 通知图标必须使用单色 png 图片。
  • @rahat 你能提供我可以使用的通知图标的示例单色 png 图像的链接吗

标签: java android push-notification android-notifications


【解决方案1】:

尝试将图标大小更改为 16x16 像素并仅使用白色,因为通知图标必须全白。

【讨论】:

  • 您还有什么建议吗?
【解决方案2】:

您需要一个 16x16 像素大小的图标并且只使用白色,但是您使用的这个 NotificationCompat.Builder 只会帮助您进入 Application Live 状态,而不是杀死状态。

【讨论】:

  • 您还有什么建议吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-11-11
  • 1970-01-01
  • 1970-01-01
  • 2017-04-11
  • 1970-01-01
  • 2017-08-25
  • 2020-12-15
相关资源
最近更新 更多