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>
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
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.
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 .
You need to create channels in order to display a notification in Oreo
.
If you use default firebase notifications, you can add channel_id
in manifest.
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="@string/default_notification_channel_id"/>
If you create notifications manually, then you need to create channel programmatically. More details on official documentation .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.