Problem description
When I try to send a Notification
in Android O I have to specify a NotificationChannel
to send to.
If I use the old method (not setting up any channel) like this NotificationCompat.Builder(this)
, the Notification
will not be displayed.
The same is for an invalid channel like this NotificationCompat.Builder(this, "invalid")
or NotificationCompat.Builder(this, "")
.
When I send a notification through Firebase Cloud Messaging and have my application in the background with no notification channel specified, it will be a notification in the "Miscellaneous" channel.
When I try to do the same in the foreground above mentioned will not work and neither will creating a notification channel with the name "Miscellaneous" and id "{package}.MISCELLANEOUS" and then sending through it. When I do that what happens is the following:
What I want to know
How do I send a notification without a channel like FCM does it, so it lands in the regular "Miscellaneous" channel?
Examples of this working
As I mentioned above, it happens with the FCM notifications, but e.g. Gmail also uses the miscellaneous channel. So how do I use it?
I believe that they would have removed the miscellaneous channel if it is normally unusable.
Shorter description
Why is this code not sending a notification to the "Miscellaneous" notification channel, it is in fact not sending any notification (only on Android O, the code works on lower Android versions).
(getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager).notify(1, NotificationCompat.Builder(this, NotificationChannel.DEFAULT_CHANNEL_ID)
.setSmallIcon(R.drawable.small_icon)
.setContentTitle(URLDecoder.decode("Title", "UTF-8"))
.setContentText(URLDecoder.decode("Text", "UTF-8"))
.setColor(ContextCompat.getColor(applicationContext, R.color.color))
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setContentIntent(PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT))
.build())