无法使用Firebase ICON android更改我的通知

时间:2016-11-09 04:56:22

标签: android firebase statusbar firebase-cloud-messaging

我最近使用过这些教程:

http://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/

来自androidhive的

但问题是我无法更改通知图标,我尝试了一切可能的方法来改变它但是即使我在 stackoverflow中搜索它也不起作用

这是我的班级

NotificationUtils.java

{{1}}

2 个答案:

答案 0 :(得分:0)

如果您想更改通知中显示的图标,请尝试更改

// notification icon
    final int icon = R.mipmap.ic_logo;

例如,如果您在**new_logo**文件夹中有Drawable图片,请将其更改为下方 -

final int icon = R.drawable.new_logo;

更改您的代码:

notification = mBuilder
            .setSmallIcon(icon)
            .setTicker(title).setWhen(0)
            .setAutoCancel(true)
            .setContentTitle(title)
            .setContentIntent(resultPendingIntent)
            .setSound(alarmSound)
            .setStyle(inboxStyle)
            .setWhen(getTimeMilliSec(timeStamp))
            .setSmallIcon(R.mipmap.ic_logo)
            .setLargeIcon(BitmapFactory.decodeResource(mContext.getResources(), icon))
            .setContentText(message)
            .build();

要:

notification = mBuilder
            .setSmallIcon(icon)
            .setTicker(title).setWhen(0)
            .setAutoCancel(true)
            .setContentTitle(title)
            .setContentIntent(resultPendingIntent)
            .setSound(alarmSound)
            .setStyle(inboxStyle)
            .setWhen(getTimeMilliSec(timeStamp))
            .setLargeIcon(BitmapFactory.decodeResource(mContext.getResources(), icon))
            .setContentText(message)
            .build();

我看到您多次设置mBuilder.setSmallIcon

答案 1 :(得分:0)

尝试一次。

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.mipmap.your_icon)
                .setContentTitle("Firebase Push Notification")
                .setContentText(messageBody)
                .setAutoCancel(true)
                .setSound(defaultSoundUri)
                .setContentIntent(pendingIntent);

        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(0, notificationBuilder.build());