question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Android 12 does not receive Push Notification

See original GitHub issue

🐛 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

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:24

github_iconTop GitHub Comments

5reactions
kunalprakash3891commented, Dec 4, 2022

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!

1reaction
lkant8commented, Aug 31, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Push notifications not working in android 12
I have a notification problem. Since I upgraded the android api 30 to api 31, the firebase "push" notifications with ionic capacitor stopped ......
Read more >
cannot receive the push notifications after upgrading ...
Make sure that all the apps installed on your phone are updated. Also, check all your notification settings. If the issue still persists,...
Read more >
Fix: Android 12 Notifications Not Working
The reason you are not getting notifications on Android 12 could simply be because your battery or power saver mode is turned on....
Read more >
Android notification issues? Try these simple 16 fixes
Disable Do Not Disturb (DND) Check app notification settings Check notification channels Check app settings Notification settings on the lock screen Disable Battery...
Read more >
Android Notifications Not Showing Up? 10 Fixes You Can Try
Android Notifications Not Showing Up? 10 Fixes You Can Try · 1. Reboot Your Phone · 2. Review the App's Notification Settings ·...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found