5

Привет, я внедряю Push-уведомления в Android с помощью Firebase. Теперь в одном круге есть маленькая иконка. Мне нужно, чтобы он показывался в большем размере. См. Изображение. И вот мой код,Как установить большую иконку в уведомлении о приложении Firebase?

  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" /> 

Как установить большой значок с этой маленькой иконки?

Here is the image

+0

Вы можете добавить код, чтобы показать свое уведомление? – amorenew

ответ

2

Я думаю, что это может быть сделано путем переопределения настроек по умолчанию.

В манифесте приложения:

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

Используйте иконку вместо @drawable/notification_icon.

Source

Надежда, что помогает

Update: Кроме того, Вы можете:

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.

Вот документация icon параметр:

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

2

См. Вы можете настроить уведомление об использовании firebase только в том случае, если ваше приложение находится на переднем плане.

Ваше уведомление будет пойман в onMessageReceived метод FirebaseMessagingService службы

Для настройки вашего уведомления, когда приложение находится на переднем плане.

Put Иконка App Drawable Папка

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 Иконка API "значок" тег

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());

1

Я пытался сделать т он то же самое. Для меня работал метод переопределения «handleIntent». Я предполагаю, что удаление super.handleIntent (намерение) сделало эту работу. Затем мы можем создать собственное уведомление, чтобы установить большой значок. Оба метода на первом и втором языках называли бы этот метод. Что-то вроде этого:

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

Больше не работает: Ошибка: handleIntent (Intent) в MyFirebaseMessagingService не может переопределить handleIntent (Intent) в FirebaseMessagingService переопределенный метод является окончательным – Annihil