Skip to content
Advertisement

Set FCM channel ID in PHP for notifications

I’m trying to send FCM notification to Android device using PHP. My code is working for devices before Android O.

In Android O, we need to set channel ID in request as well to receive notifications, which I cannot figure out how to do.

I have done the necessary setup in the app and using Firebase Console I can receive a notification, but it fails when I try sending it through the PHP script.

I also looked into the link below but it doesn’t work for me.

Android FCM define channel ID and send notification to this channel through PHP

My PHP code:

JavaScript

My notification class code is:

JavaScript

I’m sure the syntax is correct as the notification still works on devices with Android < 26.

Any help will be really appreciated. Thanks!

Advertisement

Answer

You can set your channel Id in server side PHP

PHP server side

JavaScript

I define function Notify with 4 parameters title,body,target,chid to use it just call the function and define its parameters,

You must add your channelId in your client side (Android part), with out channelId you can’t get notifications in Android 8.0 and later

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement