[英]FirebaseMessagingService push notification creation - how to set icon?
我想為FirebaseMessagingService
創建的推送通知設置圖標。 問題是這些通知是由系統內部創建的(可能在 function onStartCommand()
中,這是最終的,我無權訪問它。我不知道此通知集的圖標來自哪個來源。通常,如果您創建通知您可以通過NotificationManager
設置圖標,但此過程由 Firebase 在內部完成。我想更改圖標的原因是因為我的應用程序圖標具有透明背景(其矢量可繪制(.svg)。但由於某種原因,它顯示為正方形.
有什么方法可以修改FirebaseMessagingService
中的通知圖標嗎?
使用此 Function 進行顯示通知
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);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.