通知中心的安卓推送通知是一个灰色图标

3 人关注

我创建了一个应用程序,当你按下一个按钮时,它应该发出一个推送通知。它确实如此,但有一个问题。通知中心的图标是灰色的。但当我在一个应用程序中,在左上角看时,图标就在那里。

我的安卓版本是9,所以这不是安卓Lollipop的问题。

Some pictures:

在通知中心推送通知。

应用程序中的推送通知。

这个人也有同样的问题,通过在res文件夹里放一个透明/白色版本的图片就解决了,我做到了(而且还在那里,你可以检查我是否做对了),但对我来说并不奏效。

为什么我的通知的小图标总是灰暗的?

而且我找不到确切的问题,但有人也建议在Manifest文件中加入一行代码(如果我做得对的话,这一行代码也还在,你可以去看看)。

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

MainActivity.java。

package Package name that I chose;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.support.v4.app.NotificationCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    public void onClick(View view) {
        NotificationManager NM;
        Notification Note;
        NM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        Intent intent = new Intent("com.rj.notitfications.SECACTIVITY");
        PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this, 1, intent, 0);
        String CHANNEL_ID = "my_channel_01";
        CharSequence name = "my_channel";
        String Description = "This is my channel";
        int importance = NotificationManager.IMPORTANCE_HIGH;
        NotificationChannel mChannel = new NotificationChannel(CHANNEL_ID, name, importance);
        mChannel.setDescription(Description);
        mChannel.enableLights(true);
        mChannel.setLightColor(Color.RED);
        mChannel.enableVibration(true);
        mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
        mChannel.setShowBadge(true);
        NM.createNotificationChannel(mChannel);
        Notification.Builder builder = new Notification.Builder(MainActivity.this, CHANNEL_ID);
        builder.setAutoCancel(false);
        builder.setTicker("this is ticker text");
        builder.setContentTitle("WhatsApp Notification");
        builder.setContentText("You have a new message");
        builder.setSmallIcon(R.mipmap.whatsapp_icon);
//        builder.setLargeIcon(R.mipmap.whatsapp_icon_round);
        builder.setContentIntent(pendingIntent);
        builder.setOngoing(false);
        builder.setSubText("This is subtext...");   //API level 16
        builder.setNumber(100);
        builder.build();
        Note = builder.getNotification();
        NM.notify(11, Note);

AndroidManifest.xml。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.ste999.whatsapprelay">
    <application
        android:allowBackup="true"
        android:icon="@mipmap/whatsapp_icon"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/whatsapp_icon_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <meta-data android:name="com.google.firebase.messaging.default_notification_icon"
            android:resource="@mipmap/whatsapp_icon" />
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

而这里是链接 to my res folder