我的应用会生成通知,但我没有显示为该通知设置的图标.相反,我得到一个白色方块.
我已经尝试调整图标的大小(尺寸720x720,66x66,44x44,22x22).奇怪的是,当使用较小尺寸时,白色方块较小.
我已经google了这个问题,以及生成通知的正确方法,从我读过的代码应该是正确的.可悲的是,事情并不像他们应该的那样.
我的手机是带有Android 5.1.1的Nexus 5.问题还出现在模拟器,带有Android 5.0.1的三星Galaxy s4和带有Android 5.0.1的摩托罗拉Moto G上(我借用了这两款,现在还没有)
接下来是通知代码和两个屏幕截图.如果您需要更多信息,请随时提出要求.
谢谢你们.
@SuppressLint("NewApi") private void sendNotification(String msg, String title, String link, Bundle bundle) {
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Intent resultIntent = new Intent(getApplicationContext(), MainActivity.class);
resultIntent.putExtras(bundle);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
resultIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
Notification notification;
Uri sound = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.notificationsound);
notification = new Notification.Builder(this)
.setSmallIcon(R.drawable.lg_logo)
.setContentTitle(title)
.setStyle(new Notification.BigTextStyle().bigText(msg))
.setAutoCancel(true)
.setContentText(msg)
.setContentIntent(contentIntent)
.setSound(sound)
.build();
notificationManager.notify(0, notification);
}
Run Code Online (Sandbox Code Playgroud)

我发现我使用了一种不赞成使用的方法(notification.setLatestEventInfo())
它说使用Notification.Builder.
当我尝试创建一个新实例时,它告诉我:
Notification.Builder cannot be resolved to a type
Run Code Online (Sandbox Code Playgroud) 我有这个代码:
Notification notif;
// Build notification
Notification.Builder notifBuilder = new Notification.Builder(context);
notifBuilder.setContentIntent(pendingIntent);
notifBuilder.setContentTitle(title);
notifBuilder.setSmallIcon(icon_resId);
notifBuilder.setContentText(ne.getCaption());
notifBuilder.setDefaults(Notification.DEFAULT_ALL);
notifBuilder.setAutoCancel(autocancel);
notifBuilder.setWhen(System.currentTimeMillis());
notif = notifBuilder.build();
Run Code Online (Sandbox Code Playgroud)
在Android 4.4中运行良好.
但是,在Android 5.0中,状态栏中显示的图标是白色方块.设备锁定时显示的新"通知正文"中显示的图标是正确的.
在http://developer.android.com/reference/android/app/Notification.Builder.html中,我没有看到有关API级别21的通知图标的任何新内容
notifications android android-notification-bar android-5.0-lollipop
我需要创建一个简单的通知,如果可能的话,它会与声音和图标一起显示在通知栏中?我还需要它与Android 2.2兼容,所以我发现NotificationCompat.Builder适用于4以上的所有API.如果有更好的解决方案,请随意提及.
notifications android android-notifications android-notification-bar
我找到了这个Asset Studio来生成图标.它适用于启动器图标,但对于操作栏或通知图标,它不起作用.我输入了我的png文件并想生成图标,但Asset Studio只生成灰色圆圈.是否有其他工具可以生成操作栏和通知图标?

当使用Parse进行推送通知时,我们的应用程序始终显示应用程序的启动器图标.在最新的Android 5.1版本中,图标显示为空白(白色方块).
我尝试在元数据中设置图标:
<meta-data android:name="com.parse.push.notification_icon" android:resource="@drawable/noti_icon"/>
Run Code Online (Sandbox Code Playgroud)
根据这里的问题
但似乎没有任何效果.有任何想法吗?
我是FCM的新手.我无法让FCM使用我的应用程序图标作为通知图标,图标始终为白色空白图标.
我向mipmap文件夹导入了一个图标但似乎没有任何改变.正如一些家伙所说,这是因为在这个问题中的棒棒糖通知
但问题是,FCM通知会自动弹出,我无法让Notification构建器覆盖图标.我该怎么改变它?
android android-notifications firebase firebase-cloud-messaging firebase-notifications
我升级了android 6.0,我的应用程序有问题.
当状态栏背景颜色不是白色时,通知图标是好的.(通知图标png只有白色和alpha)
但如果某些应用将背景颜色更改为白色,则我的通知图标不会反转为黑色.
当状态栏背景颜色由其他应用设置为白色时,如何将白色通知图标反转为黑色?(我不是说如何使用彩色图标.)
下图显示了一个问题.
通知构建代码
Notification.Builder mBuilder =
new Notification.Builder(context)
.setSmallIcon(R.drawable.ic_notifications_none)
.setPriority(priority2)
.setOngoing(true);
mBuilder.setContent(generateMessageView(message));
Intent notificationIntent = new Intent(context, MainActivity.class);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent intent = PendingIntent.getActivity(context, 0,
notificationIntent, 0);
NotificationManager mNotificationManager =
(NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mBuilder.setContentIntent(intent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
Run Code Online (Sandbox Code Playgroud)值-V23/styles.xml
<style name="AppTheme" parent="android:Theme.Material.NoActionBar">
</style>
Run Code Online (Sandbox Code Playgroud)**找到解决方案**
我在drawable目录中添加了通知图标而不是drawable-*dpi.现在它正在运作.
我在android studio上设置通知图标时遇到问题.
我设置了drawable文件夹,如下所示:
我还在AndroidManifest.xml文件中设置了默认图标:
Run Code Online (Sandbox Code Playgroud)<meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@drawable/notification_icon" />
在这里,我将图标字段设置为notification_icon:https://developers.google.com/cloud-messaging/http-server-ref#downstream-http-messages-json(ps我知道这是GCM,但它有效我收到的通知除了图标之外的所有内容)
我错过了什么?我只看到一个灰色圆圈内的白色方块.
这是我的后端代码:Pushex.push(%{title: user.name, body: "message goes here", badge: 1, sound: "default", icon: "notification_icon"}, to: user.fcm_token, using: :gcm)(https://github.com/tuvistavie/pushex)
我已经创建了抬头通知。如下所示,
NotificationCompat.Builder notification = new NotificationCompat.Builder(this, channelId)
.setContentTitle("Message")
.setContentText("Recieved Successfully")
.setContentIntent(pendingIntent)
//.setColor(ContextCompat.getColor(this, R.color.green))
.setSmallIcon(R.drawable.notification_icon)
.setDefaults(Notification.DEFAULT_ALL)
.setContentIntent(pendingIntent)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setAutoCancel(true)
.setPriority(NotificationCompat.PRIORITY_HIGH);
manager.notify(m,notification.build());
Run Code Online (Sandbox Code Playgroud)
上面的代码放置在一个名为 NotificationService 的类中,该类扩展了 Service。
我可以使用下面的代码设置颜色,
setColor(ContextCompat.getColor(this, R.color.colorAccent))
Run Code Online (Sandbox Code Playgroud)
但是使用它只能设置唯一的颜色。
**我的目标不是那样。我想用它的原始颜色设置我的图标,就像在 Dominos 中一样。
在Android Manifest中添加了以下代码,
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/notification_icon" />
Run Code Online (Sandbox Code Playgroud)
当我收到推送通知时,我正在启动我的服务以显示如下所示的通知, startService(new Intent(this,NotificationService.class));
但是我收到了灰色的通知图标,而不是原始颜色。还搜索了很多网站和堆栈问题。但是关于这个问题的答案是我上面提到的在Android Manifest中放置通知图标的代码。尽管我遵循了答案,但无法将通知图标设置为多米诺骨牌。我没能找到哪里出错了。搜索了大部分发布的堆栈问题。但无法为我的问题找到合适的答案。

任何人请帮助我...
以下是我收到的通知。
如您所见,我的通知图标由两个文本组成。这两个包含两种不同的颜色。这就是我正在努力实现的目标。但我只得到灰色。设置颜色只会为 h 和 m 设置一种独特的颜色。我不想要那个。
这个没有解决办法吗??没有人做到这一点??
android push-notification firebase heads-up-notifications firebase-cloud-messaging