奇妙な問題があります。Android アプリで通知を送信する方法は 2 つあります。1 つは Android サービスから、もう 1 つは FCM 経由です。
シナリオは次のとおりです。
- アプリの起動、停止に関わらず、Android サービスから送信される通知のアイコンは正しく表示されます。
- アプリの実行中に、FCM 経由で通知を送信すると、通知アイコンが正しく表示されます。
- しかし、アプリが実行されておらず、FCM 経由で通知を送信すると、通知アイコンの代わりに白い四角が表示されます。
FCMService の私のコード:
Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle("Android App")
.setContentText(messageBody)
.setAutoCancel(true)
.setSound(defaultSoundUri)
.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());