[使用Android服务时更改状态图标

问题描述 投票:0回答:1

我正在使用前台服务。有了它,我必须显示通知,并向状态栏添加图标,如下所示:

        val notification = Builder(this, CHANNEL_ID)
        .setContentTitle("adf")
        .setSmallIcon(R.drawable.ic_baseline_settings_input_component_24)
        .setBadgeIconType(NotificationCompat.BADGE_ICON_SMALL)
        .setSmallIcon(R.drawable.ic_baseline_settings_input_component_24,2)
        .setContentText("ewr").build()

    startForeground(1, notification)

文本显示正确,但图标未更改,仅显示默认的Android。如何添加自定义图标?

android android-service
1个回答
0
投票

您是否将此添加到Android清单xml中?

<application 
    android:icon="@drawable/icon" 
    android:label="@string/app_name">

    <!-- Add your meta-data here-->
    <meta-data 
        android:name="com.google.firebase.messaging.default_notification_icon"
        android:resource="@drawable/ic_baseline_settings_input_component_24" />

    ...
</application>
© www.soinside.com 2019 - 2024. All rights reserved.