FirebasePushNotificationPlugin icon indicating copy to clipboard operation
FirebasePushNotificationPlugin copied to clipboard

Android 12 does not receive Push Notification

Open karstenspin opened this issue 2 years ago • 24 comments

🐛 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

karstenspin avatar Mar 10 '22 18:03 karstenspin

same here, I cant even upload my ABB-file to play store.

nabilakhlaque avatar Mar 20 '22 02:03 nabilakhlaque

Same problem

AlessandroLanzoni avatar Mar 23 '22 18:03 AlessandroLanzoni

Same problem

irdalan avatar Mar 24 '22 20:03 irdalan

Same

feduke-nukem avatar Apr 20 '22 07:04 feduke-nukem

What I did is before Archive, manually add android:exported="true" to PNFirebaseMessagingService in AndriodManifest.xml which can be found obj/Release/andriod.

pengham avatar Apr 27 '22 01:04 pengham

Solved Everything replacing Plugin.FirebasePushNotifications with Plugin.PushNotification from CrossGeeks in the Android Project following the sample.

Plugin.FirebasePushNotifications from Forms app continue to work properly and no issues on Android 12 anymore.

Fra9944 avatar Apr 28 '22 14:04 Fra9944

I tried Plugin.PushNotification, I still have to manually add android:exported="true" like I did for Plugin.FirebasePushNotifications.

pengham avatar May 04 '22 06:05 pengham

I identified a possible solution.

I am building my app using the Android sdk version android:minSdkVersion="26" android:targetSdkVersion="31" (Android 12) and deploying it to an Android 12 device (emulator). The events were not executed (doesn't matter the state of the app) however the Notification message where received by Android Fcm if the application was closed or in background.

By removing the following lines from AndroidManifest.xml the events started to work:

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

I have experimented with the android:exported=true/false value but this didn't change anything in my case. I couldn't test the behaviour for a closed/killed app, however events work for an application in foreground and background for the following test data

"to": "Device-Token",
    "priority": "high",
    "notification" : {
        "title": "New message",
        "body" : "You received a new message.",
        "icon": "app_icon",
        "sound": "default",
        "color": "#bb2231",
        "click_action": "message",
        "content_available" : true
    }
"to": "Device-Token",
    "priority": "high",
    "data" : {
        "title": "New message",
        "text" : "You received a new message.",
        "icon": "app_icon",
        "sound": "default",
        "color": "#bb2231"
    }

andyzukunft avatar Jun 15 '22 13:06 andyzukunft

I identified a possible solution.

I am building my app using the Android sdk version android:minSdkVersion="26" android:targetSdkVersion="31" (Android 12) and deploying it to an Android 12 device (emulator). The events were not executed (doesn't matter the state of the app) however the Notification message where received by Android Fcm if the application was closed or in background.

By removing the following lines from AndroidManifest.xml the events started to work:

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

I have experimented with the android:exported=true/false value but this didn't change anything in my case. I couldn't test the behaviour for a closed/killed app, however events work for an application in foreground and background for the following test data

"to": "Device-Token",
    "priority": "high",
    "notification" : {
        "title": "New message",
        "body" : "You received a new message.",
        "icon": "app_icon",
        "sound": "default",
        "color": "#bb2231",
        "click_action": "message",
        "content_available" : true
    }
"to": "Device-Token",
    "priority": "high",
    "data" : {
        "title": "New message",
        "text" : "You received a new message.",
        "icon": "app_icon",
        "sound": "default",
        "color": "#bb2231"
    }

@andyzukunft Are you able to publish to Play Store without that line in the AndroidManifest.xml file?

irdalan avatar Jun 16 '22 12:06 irdalan

@andyzukunft Are you able to publish to Play Store without that line in the AndroidManifest.xml file?

@irdalan I did some testing as you requested.

  1. Build in Release works (including DEX and code shrink)
  2. Signing package works
  3. Uploading package to Google Play Console works
  4. App has been released on closed track (alpha, with control/checks by Google)
  5. Notifications work as described in my previous post

Altough I was really worried after I read your question. Don't ask me why this works (because of Android 12 sdk target?) and why it might have been required before the current sdk target change.

andyzukunft avatar Jun 17 '22 11:06 andyzukunft

@andyzukunft Is there any other option besides that?

anuj9090 avatar Aug 17 '22 06:08 anuj9090

@anuj9090 I don't know if there are other possible options. My stated solution works so far. I have no problem publishing my app to Google Play Closed Track.

andyzukunft avatar Aug 17 '22 20:08 andyzukunft

@anuj9090 have you found any solution?

Rishi2611 avatar Aug 24 '22 13:08 Rishi2611

facing same issue

Rishi2611 avatar Aug 24 '22 13:08 Rishi2611

@Rishi2611 No, I'm still struggling to resolve the issue.

anuj9090 avatar Aug 24 '22 17:08 anuj9090

@anuj9090 Please follow these steps:- Install package Xamarin.Firebase.Common (>= 120.0.0.5) Xamarin.Firebase.Messaging (>= 122.0.0.5) Xamarin.GooglePlayServices.Base (>= 118.0.1) Xamrarin.Firebase.Ide(121.1.0.6) and update FirebasePushNotificationPlugin to 3.4.22

Also Remove unnecessary tags FCM from AndroidMainfest File Such as :-

After this clean and then Delete Bin and ObJ Folder of each Project and then Rebuild Project and Deploy

Problem will be solved

Rishi2611 avatar Aug 25 '22 10:08 Rishi2611

Same issue

aishwaryarh avatar Aug 26 '22 15:08 aishwaryarh

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

lkant8 avatar Aug 31 '22 09:08 lkant8

you have to subscribe to topic

sirajalam avatar Oct 18 '22 10:10 sirajalam

facing same issue, did anyone got the solution?

gautamsinh avatar Nov 01 '22 11:11 gautamsinh

add this to your app/gradle in dependencies

implementation "com.google.firebase:firebase-iid:21.1.0" implementation "com.google.firebase:firebase-messaging:22.0.0"

yashpyraj avatar Nov 22 '22 14:11 yashpyraj

Update your firebase version to 23.1.0, This resolves the Android 12 issue.

You can add that to app/build.gradle implementation 'com.google.firebase:firebase-messaging:23.1.0

VM8198 avatar Dec 03 '22 07:12 VM8198

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!

kunalprakash3891 avatar Dec 04 '22 04:12 kunalprakash3891

@kunalprakash3891 How was your complete XML androidmanifest?

ivanteles avatar Jul 25 '23 19:07 ivanteles