在Android12以上的版本 通知使用svg圖片,會(huì)被設(shè)置為灰色埋泵。(tint灰)
無鏤空的圖標(biāo)
有鏤空的圖標(biāo)
國(guó)內(nèi)的可以這樣,三星的原生的不能這么搞
直接使用png
Starting in Android 12 (API level 31), the system derives the icon color from the notification color you set in the app. If the app doesn't set the color, it uses the system theme color.
Previously, the color was gray.
Previously, the color was gray.
簡(jiǎn)單解決辦法市殷。不用svg圖纫事,直接用png圖標(biāo)就行
PS:
修改Firebase默認(rèn)的通知圖標(biāo)
在AndroidManifest.xml中設(shè)置
<!-- Set custom default icon. This is used when no icon is set for incoming notification messages.
See README(https://goo.gl/l4GJaQ) for more. -->
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/ic_stat_ic_notification" />
<!-- Set color used with incoming notification messages. This is used when no color is set for the incoming
notification message. See README(https://goo.gl/6BKBk7) for more. -->
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/colorAccent" />
firebase圖標(biāo)設(shè)置代碼
com.google.firebase.messaging.DisplayNotification.handleNotification
boolean handleNotification() {
if (params.getBoolean(MessageNotificationKeys.NO_UI)) {
return true; // Fake notification, nothing else to do
}
if (isAppForeground()) {
return false; // Needs to be passed to onMessageReceived
}
ImageDownload imageDownload = startImageDownloadInBackground();
CommonNotificationBuilder.DisplayNotificationInfo notificationInfo =
CommonNotificationBuilder.createNotificationInfo(context, params);
waitForAndApplyImageDownload(notificationInfo.notificationBuilder, imageDownload);
showNotification(notificationInfo);
return true;
}
具體抓取icon
private static int getSmallIcon(
PackageManager packageManager,
Resources resources,
String pkgName,
String resourceKey,
Bundle manifestMetadata) {
if (!TextUtils.isEmpty(resourceKey)) {
// if the message contains a specific icon name, try to find it in the resources.
int iconId = resources.getIdentifier(resourceKey, "drawable", pkgName);
if (iconId != 0 && isValidIcon(resources, iconId)) {
return iconId;
}
// Also try the mipmap resources if not found in drawable
iconId = resources.getIdentifier(resourceKey, "mipmap", pkgName);
if (iconId != 0 && isValidIcon(resources, iconId)) {
return iconId;
}
Log.w(
TAG, "Icon resource " + resourceKey + " not found. Notification will use default icon.");
}
int iconId = manifestMetadata.getInt(METADATA_DEFAULT_ICON, 0);
if (iconId == 0 || !isValidIcon(resources, iconId)) {
// No icon found so far. Falling back to default App icon (launcher icon).
try {
/* flags= */ iconId = packageManager.getApplicationInfo(pkgName, 0).icon;
} catch (PackageManager.NameNotFoundException e) {
Log.w(TAG, "Couldn't get own application info: " + e);
}
}
if (iconId == 0 || !isValidIcon(resources, iconId)) {
// Wow, app doesn't have a launcher icon. Falling back on icon-placeholder used by the OS.
iconId = android.R.drawable.sym_def_app_icon;
}
return iconId;
}