Firebase消息服务推送通知创建 - 如何设置图标?



我想为FirebaseMessagingService创建的推送通知设置图标。问题是这些通知是由系统内部创建的(可能在功能onStartCommand()中,这是最终的,我无法访问它。我不知道此通知集的图标来自哪个来源。通常,如果您创建通知,则可以通过NotificationManager设置图标,但此过程由Firebase内部完成。我想更改图标的原因是因为我的应用程序图标具有透明背景(其矢量可绘制对象 (.svg(。但由于某种原因,它显示为正方形。

有什么方法可以修改FirebaseMessagingService内的通知图标吗?

使用此功能显示通知

public void showNotificationMessage(final String title, final String message,Intent intent) {
Random random = new Random();
NotificationManager notifManager = null;
if (notifManager == null) {
notifManager = (NotificationManager)mContext.getSystemService(Context.NOTIFICATION_SERVICE);
}
NotificationCompat.Builder mBuilder=null;
if (TextUtils.isEmpty(message))
return;
final int icon = R.mipmap.ic_launcher;
String notificationId = String.format("%04d", random.nextInt(10000));
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
final PendingIntent resultPendingIntent =
PendingIntent.getActivity(
mContext,
Integer.parseInt(notificationId),
intent,
PendingIntent.FLAG_CANCEL_CURRENT
);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel mChannel = notifManager.getNotificationChannel("Test");
if (mChannel == null) {
mChannel = new NotificationChannel("Test", title, importance);
mChannel.enableVibration(true);
notifManager.createNotificationChannel(mChannel);
}
mBuilder = new NotificationCompat.Builder(mContext, "Test");
}else{
mBuilder = new NotificationCompat.Builder(mContext, "Test");
}
Notification notification;
notification = mBuilder.setTicker(title)
.setAutoCancel(true)
.setContentTitle(title)
.setContentIntent(resultPendingIntent)
//.setStyle(inboxStyle)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentText(message)
.build();
NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(Integer.parseInt(notificationId), notification);

}

相关内容

  • 没有找到相关文章

最新更新