I created an app that should send out an push notification when you press a button. It does but there is an issue: The icon in the notification center is grayed out. but when I'm in an app and look in the top left corner the icon is there.
My Android version is 9 so this isn't the android lollipop issue
Some pictures:
Push notification in notification center:
Push notification in apps:
This person had the same issue and it was resolved by putting a transparent/white version from the image in the res folder I did it (and it's still there so you can check if I did it right) but it didn't work for me:
Why is my smallIcon for Notifications always greyed out?
and I can't find the exact question but someone also suggested to put a line of code in the Manifest file (which is also still there which you can check out if I did it right):
<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>
and here's a link to my res folder
I expect someone can point out my error and make it so that the icon is also there in the notification center instead of a grey circle