How to set a large icon in a notification about a Firebase application?

Hi, I am using push notifications in Android using Firebase. Now in one circle there is a small icon. I need it to appear in a larger size. See 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 to set a large icon with this small icon?

Here is the image

+5
source share
3 answers

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

In the application manifest:

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

Use the icon instead of @drawable/notification_icon .

A source

Hope that helps

Update: Also see:

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

The icon setting can be used to indicate the ability to draw in your application. If you want to use R.drawable.foo just pass foo.

Here is the documentation for the icon options:

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

+3
source

See You can set up a notification about your Firebase only if your application is in the foreground.

Your notification will be detected in the onMessageReceived FirebaseMessagingService service method

Set up your notification when your application is in the foreground.

Put icon from application graphical 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 an icon from the 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()); 
+2
source

I tried to do the same. The override method "handleIntent" worked for me. I guess removing super.handleIntent (intent) did the job. Then we can create our own notification to set a large icon. Both methods in the first and second languages ​​would call this method. Something like that:

 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(); } } 
+1
source

Source: https://habr.com/ru/post/1262338/


All Articles