[英]Android firebase push notification change/Remove small grey icon
我有這段代碼用於生成通知。
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(mCtx);
Notification notification;
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
notification = mBuilder.setSmallIcon(R.mipmap.ic_launcher).setTicker(title).setWhen(0)
.setAutoCancel(true)
.setContentIntent(resultPendingIntent)
.setContentTitle(title)
.setSmallIcon(R.mipmap.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(mCtx.getResources(), R.mipmap.ic_launcher))
.setContentText(message)
.setSound(defaultSoundUri)
.build();
notification.flags |= Notification.FLAG_AUTO_CANCEL;
// mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
NotificationManager notificationManager = (NotificationManager) mCtx.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(ID_SMALL_NOTIFICATION, notification);
您需要刪除此:
setSmallIcon(R.mipmap.ic_launcher);
因為這是小圖標,大圖標是大圖標setLargeIcon(..)
檢查此以獲取更多信息: https : //developer.android.com/reference/android/app/Notification.Builder.html#setSmallIcon (int,int)
setSmallIcon(整數圖標)設置小圖標資源,該資源將用於表示狀態欄中的通知。 除非另外指定了大圖標,否則展開視圖的平台模板將在左側繪制此圖標,在這種情況下,小圖標將移至右側。
你可以這樣做:
NotificationCompat.Builder notificationBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(this)
.setContentIntent(pendingIntent)
.setContentTitle(dataTitle)
.setContentText(dataMessage)
.setSound(defaultSoundUri);
Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
notificationBuilder.setLargeIcon(largeIcon);
NotificationCompat.Builder notificationBuilder = new
NotificationCompat.Builder(this);
notificationBuilder.setSmallIcon(R.drawable.logo)
.setContentTitle(title)
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
您的圖標R.mipmap.ic_launcher是一個矩形。 操作系統將其着色為白色-這樣您就擁有了一個白色矩形。 解決方案是在這種情況下使用自定義圖標(如果要保持啟動器圖標不變)。 我不知道您的圖標到底是什么,但是嘗試導出您的啟動器圖標以使用透明背景(也許來自https://materialdesignicons.com/-選擇其中一個圖標,單擊</>
圖標,然后選擇“查看向量可繪制”-而不是將其用作通知的小圖標)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.