FirebasePushNotificationPlugin: Android 12 does not receive Push Notification

๐Ÿ› Bug Report

On Android 12 my app is not receiving push notifications. Phones with Android 11 and below do receive the push notifications.

Added manually to manifest:

<service android:name="crc6494e14b9856016c30.PNFirebaseMessagingService" android:exported="false">
	<intent-filter>
		<action android:name="com.google.firebase.MESSAGING_EVENT" />
	</intent-filter>
</service>

I tried it also with android:exported=โ€œtrueโ€ but same behaviour - no notifications on Android 12.

Hope that someone has a solution for this!

Used: Firebase.Plugin 3.4.1 TargetFramework Android 12 JDK 11

About this issue

Most upvoted comments

I managed to get it work for Android 12 and Android 13 by using a combination of suggestions mentioned here;

First, I updated all my existing packages.

Second, I installed the latest version of the following packages as described by @Rishi2611; Xamarin.Firebase.Common Xamarin.Firebase.Messaging Xamarin.GooglePlayServices.Base Xamrarin.Firebase.Iid

Third, I added the following to my AndroidManifest.xml file;

<service android:name="crc6494e14b9856016c30.PNFirebaseMessagingService" android:exported="false">
	<intent-filter>
		<action android:name="com.google.firebase.MESSAGING_EVENT" />
	</intent-filter>
</service>

And finally the fourth, to get it to work for Android 13, I added the following permission to the AndroidManifest.xml (this permission is requred for Anrdoid 13 and wonโ€™t work without it) <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

Then added the following code to MainActivity.cs to the end of OnCreate to request push notification permissions from the user on app start-up;

if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Tiramisu)
{
    if (ContextCompat.CheckSelfPermission(this, Manifest.Permission.PostNotifications) != (int)Permission.Granted)
    {
        ActivityCompat.RequestPermissions(this, new String[] { Manifest.Permission.PostNotifications }, 1);
    }
}

Make sure the target version is set to Android 13 (API Level 33).

Hopefully this helps someone out there whoโ€™s still struggling with this!

i have added in my manifest file

<service android:name="crc6494e14b9856016c30.PNFirebaseMessagingService" android:exported="false">
	<intent-filter>
		<action android:name="com.google.firebase.MESSAGING_EVENT" />
	</intent-filter>
</service>

this is my

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {

            NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
            String channelId = getString(R.string.default_notification_channel_id);
            String name = getString(R.string.app_name);
            int importance = NotificationManager.IMPORTANCE_HIGH;
            NotificationChannel mChannel = new NotificationChannel(channelId, name, importance);
            mChannel.setDescription("hello");
            mChannel.enableLights(true);
            mChannel.setLightColor(Color.RED);
            mChannel.enableVibration(true);
            mChannel.setVibrationPattern(new long[]{100, 200, 300});
            notificationManager.createNotificationChannel(mChannel);
            Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
// Set the notification parameters to the notification builder object

            Intent intent1;
            if (!mSession.getHasLoging()) {
                intent1 = new Intent(getApplicationContext(), BrokerActivity.class);
            } else if (mSession.getHasLoging() && mSession.getLoginType().equals("broker")) {
                intent1 = new Intent(getApplicationContext(), BrokerActivity.class);
            } else {
                intent1 = new Intent(getApplicationContext(), ClientActivity.class);
            }

            Bundle bundle = new Bundle();
            bundle.putString("coming_from", "notification");
            intent1.putExtras(bundle);
            PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 123, intent1, PendingIntent.FLAG_UPDATE_CURRENT);
            @SuppressLint("WrongConstant") NotificationCompat.Builder notificationBuilder
                    = new NotificationCompat.Builder(getApplicationContext(), channelId)
                    .setSmallIcon(R.mipmap.notification_icon) //your app icon
                    .setBadgeIconType(R.mipmap.notification_icon) //your app icon
                    .setChannelId(channelId)
                    .setContentTitle(object.optString("title"))
                    .setSound(defaultSoundUri)
                    .setContentText(object.optString("text"))
                    .setAutoCancel(false).setContentIntent(pendingIntent);
// Set the image for the notification
            if (!TextUtils.isEmpty(object.optString("imgpath"))&&!object.optString("imgpath").equalsIgnoreCase("null")) {
                Bitmap bitmap = getBitmapFromUrl(object.optString("imgpath"));
                notificationBuilder.setStyle(
                        new NotificationCompat.BigPictureStyle()
                                .bigPicture(bitmap)
                                .bigLargeIcon(null)
                ).setLargeIcon(bitmap);
            }
            notificationBuilder.build().flags |= Notification.FLAG_AUTO_CANCEL;
            notificationManager.notify(1, notificationBuilder.build());


        } else {
            sendNotification(object);
        }

but still not getting notification