Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a bigger icon in Firebase app notification?

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

like image 320
Sirilcs Avatar asked Jan 05 '17 07:01

Sirilcs


People also ask

How do I send a picture in FCM notification?

Stay organized with collections Save and categorize content based on your preferences. The FCM HTTP v1 API and the Notifications composer support sending image links in the payload of a display notification, for image download to the device after delivery.


3 Answers

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

like image 165
ʍѳђઽ૯ท Avatar answered Oct 24 '22 09:10

ʍѳђઽ૯ท


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();
    }
}
like image 35
CCOONOK Avatar answered Oct 24 '22 09:10

CCOONOK


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());
like image 24
Gulnaz Ghanchi Avatar answered Oct 24 '22 10:10

Gulnaz Ghanchi