【发布时间】: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