【问题标题】:Q: Change notification icon in Android StudioQ:在 Android Studio 中更改通知图标
【发布时间】:2017-10-19 02:14:26
【问题描述】:

我配置了应用程序图标(图 1),但通知图标(通过 Firebase 发送的通知)显示一个灰色矩形(图 2)。 通过 Android Studio 2.3 或通过脚本更改通知图标图像(图 2)的过程是什么?

清单

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.studioshow.studioshow">
<uses-permission android:name="android.permission.INTERNET" />
<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

    <activity android:name=".MainActivity">

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />


        </intent-filter>
    </activity>
</application>

【问题讨论】:

  • 在创建时添加通知代码。需要更多信息。

标签: android firebase firebase-cloud-messaging android-notifications


【解决方案1】:

在清单文件中。设置元数据。 以下代码是我的情况。

   <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.NoTitleBar"  >
        <activity
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>


        <service
            android:name=".MyFirebaseMessagingService">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT"/>
            </intent-filter>
        </service>

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

    </application>

【讨论】:

  • 包含元日期后,图标和颜色更改成功。
【解决方案2】:

编辑:我的回答不相关:我没有阅读有关Firebase 消息传递部分的信息。


只需使用setSmallIcon(int),由NotificationBuilder 及其对应的Compat 提供。

您可以通过传递从resource 文件夹中检索图标,例如 R.drawable.my_icon 作为参数。

【讨论】:

    猜你喜欢
    • 2019-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多