当前位置: 首页 > 知识库问答 >
问题:

如何在Firebase应用程序通知中设置更大的图标?

吕博耘
2023-03-14

您好,我正在使用Firebase在Android中实现推送通知。现在,有一个小图标显示在一个圆圈内。我需要更大尺寸的。请看图片。这是我的密码,

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

如何从这个小图标设置大图标?

共有3个答案

田翔
2023-03-14

请参阅仅当您的应用处于前台时,您才能自定义Firebase通知。

FirebaseMessagingService服务的onMessageReceived方法将捕获您的通知

在应用程序位于前台时自定义通知。

从App Drawable文件夹放置图标

html lang-html prettyprint-override">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());
宗政鸿志
2023-03-14

我试着做同样的事情。重写“handleIntent”方法对我很有效。我想删除超级。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();
    }
}
燕翼
2023-03-14

我认为可以通过覆盖默认设置来实现。

在应用程序清单中:

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

使用您的图标,而不要使用drawable/notification_图标。

来源

希望有帮助

更新:还有,看看:

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

icon参数可用于指定应用程序中的绘图。如果你想使用R.drawable。福,把福递给我。

以下是参数文档:

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

 类似资料:
  • 问题内容: 我刚刚在Windows上创建了我的第一个应用程序。 我如何给它一个图标? 似乎没有任何构建标记可以执行此操作,而且我知道golang不支持资源。 问题答案: 您可以使用akavel / rsrc之 类的工具来生成一个.syso文件,该文件中嵌入了指定的资源,旨在在构建Win32可执行文件时供Go链接器使用。 以lxn / walk应用程序为例,该应用程序将其他元数据嵌入其可执行文件中。

  • 我正在为windows编程JavaFX应用程序,并希望在这些情况下看到应用程序图标 快捷图标(在桌面上,windows开始菜单上) 任务栏图标(即使应用程序固定在任务栏上) (可选).exe-图标 下面的代码似乎很好地完成了它的工作,但是当应用程序运行时,我右按任务栏选择“pin this program”,默认的咖啡杯又会显示出来。当右键单击任务栏项时,杯子就会显示出来-.- 编辑:越来越傻了…

  • 我正在尝试使通知振铃当应用程序没有运行在iOS。

  • 当应用程序在后台时,如何更新包含数据负载的Firebase推送通知?有没有办法在通知中指定通知id给Firebase API? 完整的项目在github https://github.com/akshatashan/FireBaseCloudMessagingDemo中

  • 问题内容: 我知道我可以为每种形式或根形式指定一个,然后它将级联到所有子形式,但是我想有一种方法可以覆盖所有形式的默认Java Coffee Cup,即使那些形式我可能会忘记。 有什么建议? 问题答案: 您可以将根形式(我假设是)作为自己的子类,并将标准功能放入其构造函数中,例如: 您也可以在此处捆绑其他标准内容,例如将框架的窗口度量标准存储为用户首选项,管理初始窗格等。 此框架产生的任何新框架也

  • 如何设置电子应用程序的应用程序图标? 我正在尝试