How to set a bigger icon in Firebase app notificat

2019-03-26 18:05发布

Hi i am implementing Push Notifications in Android using Firebase. Now, there is a small icon showing inside one circle. I need it to show in bigger size. Please see the image. And here is my code,

            android:id="@+id/relativeNotification"

            android:layout_width="192dp"
            android:layout_height="192dp"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true">

            <com.inspius.coreapp.widget.TintableImageView
                android:layout_width="192dp"
                android:layout_height="192dp"
                android:layout_centerHorizontal="true"
                android:layout_centerVertical="true"
                android:layout_gravity="center_vertical"
                android:contentDescription="@string/app_name"
                android:src="@drawable/ic_launcher"
                app:tint="@color/custom_icon_video_detail_selector" />

How do i set large icon from this small icon?

Here is the image

3条回答
小情绪 Triste *
2楼-- · 2019-03-26 18:29

I think it can be done by overriding the default settings.

In your application manifest:

<meta-data
        android:name="com.google.firebase.messaging.default_notification_icon"
        android:resource="@drawable/notification_icon" />

Use your icon instead of @drawable/notification_icon.

Source

Hope that helps

Update: Also, Have a look:

https://github.com/firebase/quickstart-android/issues/4#issuecomment-221344318

The icon parameter can be used to specify a drawable within your app. If you want to use R.drawable.foo, just pass foo.

Here is the icon parameter documentation:

https://firebase.google.com/docs/cloud-messaging/http-server-ref#notification-payload-support

查看更多
Evening l夕情丶
3楼-- · 2019-03-26 18:35

I tried to do the same thing. Overriding "handleIntent" method worked for me. I guess removing the super.handleIntent(intent) made this work. Then we can build our own notification to set the large icon. Both foreground and background cases would call this method. Something like this:

public class YourMessagingService extends FirebaseMessagingService {

    @Override
    public void handleIntent(Intent intent) {
        // super.handleIntent(intent);

        // get intent codes....

        NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
        Notification notification = builder
                .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.yourLargeIcon))
                .setSmallIcon(R.drawable.yourSmallIcon)
                .setContentTitle("yourTitle")
                .setContentText("yourText")
                .build();

        NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        notificationManager.notify(111, notification);
    }

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        super.onMessageReceived(remoteMessage);
    }

    @Override
    public void onDeletedMessages() {
        super.onDeletedMessages();
    }
}
查看更多
女痞
4楼-- · 2019-03-26 18:37

See You can customize your firebase notification only when your app is in foreground.

Your notification will be caught in onMessageReceived method of FirebaseMessagingService service

To Customize your notification when your app is in foreground.

Put Icon From App Drawable Folder

Bitmap largeIcon = BitmapFactory.decodeResource(getResources(), R.drawable.icons);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setLargeIcon(largeIcon)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(remoteMessage.getNotification().getTitle())
.setContentText(remoteMessage.getNotification().getBody());
NotificationManager manager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
            manager.notify(0, builder.build());

Put Icon From API "icon" tag

String name = remoteMessage.getNotification().getIcon();
URL url_value = new URL(name);
Bitmap mIcon1 = BitmapFactory.decodeStream(url_value.openConnection().getInputStream());
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
.setLargeIcon(mIcon1)
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle(remoteMessage.getNotification().getTitle())            .setContentText(remoteMessage.getNotification().getBody());
NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
            manager.notify(0, builder.build());

查看更多
登录 后发表回答