Q: Change notification icon in Android Studio

我与影子孤独终老i 提交于 2019-12-23 04:12:38

问题


I configured the application icon (Image 1), but the notification icon (Notification sent via Firebase) shows a gray rectangle (Image 2). What is the procedure for changing the notification icon image (Image 2) via Android Studio 2.3 or via script?

Manifest

<?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>


回答1:


In manifest file. Set meta data. Following code is my case.

   <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:


EDIT: My answer is not relevant: I did not read about the Firebase messaging part.


Simply use setSmallIcon(int), provided by NotificationBuilder and its Compat counterpart.

You can retrieve the icon from your resource folder by passing, e.g. R.drawable.my_icon as parameter.



来源:https://stackoverflow.com/questions/46821916/q-change-notification-icon-in-android-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!