Reputation: 24325
The code below doesn't seem to be showing a notification on my emulator. I upgraded from the deprecated Firebase code to the new stuff, with channels. Is there something I should look into?
<application android:icon="@drawable/icon" android:allowBackup="false" android:label="@string/application_label" android:theme="@style/Theme">
<meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@drawable/icon" />
<meta-data android:name="com.google.firebase.messaging.default_notification_color" android:resource="@color/accentColor" />
<meta-data android:name="com.google.firebase.messaging.default_notification_channel_id" android:value="@string/default_notification_channel_id" />
......
<service
android:name="com.exposure.services.ExposureFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT"/>
</intent-filter>
</service>
</application>
Upvotes: 0
Views: 1296
Reputation: 37
Please use Notification channel before creating notification according to Google developer side https://developer.android.com/training/notify-user/channels
Upvotes: 0
Reputation: 16379
From Android Oreo, you must use channels to create notifications.
Starting in Android 8.0 (API level 26), all notifications must be assigned to a channel. For each channel, you can set the visual and auditory behavior that is applied to all notifications in that channel. Then, users can change these settings and decide which notification channels from your app should be intrusive or visible at all.
Caution: If you target Android 8.0 (API level 26) and post a notification without specifying a notification channel, the notification does not appear and the system logs an error.
Read more docs at: https://developer.android.com/training/notify-user/channels
Apparently, you have used a notification channel for your notifications, but haven't created a notification channel associated with that id. So you will need to create a notification channel before creating notifications.
Example to create a notification channel (maybe in your FCM Service class) is given below:
@Override
public void onCreate() {
super.onCreate();
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
// Make sure you use the same channel id ("default" in this case)
// while creating notifications.
NotificationChannel channel = new NotificationChannel("default", "Default Channel",
NotificationManager.IMPORTANCE_HIGH);
channel.setDescription("Default Notification Channel");
NotificationManager notificationManager = (NotificationManager)
getSystemService(NOTIFICATION_SERVICE);
if (notificationManager != null) {
notificationManager.createNotificationChannel(channel);
}
}
}
Upvotes: 2