【发布时间】:2019-09-03 17:30:40
【问题描述】:
我创建了一个应用程序,当您按下按钮时应该会发送推送通知。可以,但是有一个问题:通知中心的图标是灰色的。但是当我在应用程序中并查看左上角时,图标就在那里。
我的 Android 版本是 9,所以这不是 android lollipop 问题
一些图片:
在通知中心推送通知:
在应用中推送通知:
这个人有同样的问题,通过将图像中的透明/白色版本放入 res 文件夹中解决了这个问题我做了(它仍然在那里,所以你可以检查我是否做对了)但它没有为我工作:
Why is my smallIcon for Notifications always greyed out?
我找不到确切的问题,但有人还建议在 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>
这是 a link 到我的 res 文件夹
我希望有人能指出我的错误并使其图标也出现在通知中心而不是灰色圆圈中
【问题讨论】: