android 前台服务图标,Android通知图标问题

在Android应用中,当通过服务发送通知时,通知图标始终正常显示。然而,当应用程序未运行且使用FCM(Firebase Cloud Messaging)发送通知时,通知图标被替换为白色方块。问题可能出在FCMService的配置或通知构建上。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我有一个奇怪的问题.我有两种方法可以在我的Android应用中发送通知;一个来自Android服务,另一个来自FCM.

方案如下:

>无论应用程序是否正在运行,Android服务发送的通知图标都会正确显示.

>当应用程序运行时,如果我通过FCM发送通知,则仍会正确显示通知图标.

>但是如果应用程序没有运行并且我通过FCM发送通知,则会显示白色方块而不是通知图标.

我在FCMService中的代码:

Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)

.setSmallIcon(R.drawable.notification_icon)

.setContentTitle("Android App")

.setContentText(messageBody)

.setAutoCancel(true)

.setSound(defaultSoundUri)

.setContentIntent(pendingIntent);

NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

notificationManager.notify(0, notificationBuilder.build());

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值