我创建了一个应用程序,当你按下按钮时,它应该发送推送通知。它确实可以发送,但存在一个问题:通知中心中的图标变灰。但是,当我在应用程序中并查看左上角时,图标是存在的。
我的Android版本是9,因此这不是安卓棒棒糖问题。
一些图片:
通知中心中的推送通知: 在应用程序中的推送通知: 这个人遇到了同样的问题,通过将图像的透明/白色版本放入res文件夹中解决了这个问题。我也这样做了(它仍然在那里,所以你可以检查我是否做对了),但对我没有用:
我的Android版本是9,因此这不是安卓棒棒糖问题。
一些图片:
通知中心中的推送通知: 在应用程序中的推送通知: 这个人遇到了同样的问题,通过将图像的透明/白色版本放入res文件夹中解决了这个问题。我也这样做了(它仍然在那里,所以你可以检查我是否做对了),但对我没有用:
我找不到确切的问题,但有人建议在清单文件中加入一行代码(也仍然在那里,如果我做对了,你可以查看):
<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>
这里有一个资源文件夹的链接。
我希望有人能指出我的错误,并使得图标也能在通知中心中显示,而不是一个灰色的圆圈。