Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FCM notifications not working in Android latest version OREO

FCM notifications are not working in Android latest version OREO.

Below is my code:

AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example">

    <uses-permission android:name="android.permission.CALL_PHONE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/luncher_logo"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/luncher_logo"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".WelcomeActivity">
            <intent-filter>
                <action android:name="com.example.action.MAIN" />

                <category android:name="com.example.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".MainActivity" />


        <service android:name=".firebase.MyFirebaseMessagingService">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>
        <service android:name=".firebase.FirebaseIDService">
            <intent-filter>
                <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
            </intent-filter>
        </service>
</manifest>
like image 232
gurunath Avatar asked Dec 06 '25 04:12

gurunath


2 Answers

In Android Oreo making channel is important,When yo create notification you must pass the channel id,or your notification won't show up in Oreo devices.

more information

quick fix is: use setChannelId method in notification class.

 Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
  .setSmallIcon(R.drawable.ic_notif_icon)
  .setContentTitle("testTitle")
  .setContentText(messageBody)
  .setAutoCancel(true)
  .setSound(defaultSoundUri)
  .setChannelId("testChannelId") // set channel id
  .setContentIntent(pendingIntent);

complete answer in this link.

like image 120
hossein mas Avatar answered Dec 07 '25 18:12

hossein mas


From Android 8.0 (API level 26+), notification channels are supported and recommended.

FCM provides a default notification channel with basic settings.

If you prefer to create and use your own default channel, set default_notification_channel_id to the ID of your notification channel object as shown below.

FCM will use this value whenever incoming messages do not explicitly set a notification channel.

    <meta-data
        android:name="com.google.firebase.messaging.default_notification_channel_id"
        android:value="@string/default_notification_channel_id"/>

You can create channel id from this link

like image 38
Deep Patel Avatar answered Dec 07 '25 18:12

Deep Patel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!