FirebasePushNotificationPlugin
FirebasePushNotificationPlugin copied to clipboard
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
same here, I cant even upload my ABB-file to play store.
Same problem
Same problem
Same
What I did is before Archive, manually add android:exported="true" to PNFirebaseMessagingService in AndriodManifest.xml which can be found obj/Release/andriod.
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.
I tried Plugin.PushNotification, I still have to manually add android:exported="true" like I did for Plugin.FirebasePushNotifications.
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"
}
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?
@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.
- Build in Release works (including DEX and code shrink)
- Signing package works
- Uploading package to Google Play Console works
- App has been released on closed track (alpha, with control/checks by Google)
- 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 Is there any other option besides that?
@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.
@anuj9090 have you found any solution?
facing same issue
@Rishi2611 No, I'm still struggling to resolve the issue.
@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
Same issue
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
you have to subscribe to topic
facing same issue, did anyone got the solution?
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"
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
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 How was your complete XML androidmanifest?