Fixing push notifications on Android 8. Aka channels
Aug 19, 2018
1 minute read
Upgrading your target SDK to 26+ (Android 8) can break your push notifications all of a sudden. Fortunatelly it´s very easy to fix.
Android 8 (API level 26) expects any notification to use a Channel. So we need to implement them but only when the API level is 26+. Channels should be ignored otherwise because they won´t be available, meaning that your app will throw an exception if you try to use them.
We will create a default channel to be used when any push notification arrives. You can actually create multiple channels but I bet most applications will be just fine with one.
I´ts a good idea to create the default channel at app start, either on your main activity or your custom Application OnCreate() override:
And last, but not least, you need to make and slight modification to the code that creates the notification.
From now on your push notifications will start working again on Android 8.
Pixyll is an open-source Jekyll theme that's built by John Otander.
When he's not writing code and building things, he likes to ski. A. Lot.