Skip to content

Could not receive the push notification on OnMessageReceived while swipe away app #476

Description

@ebinroy

When app is in foreground (visible on screen)/background (minimize the app) function OnMessageReceived is called and notification message is displayed as expected. When I swipe of the app or click close all then I am not getting the notification message, While I am getting notification for other commercial app if I close also.. I am using Data only message

Android manifest

<application android:label="MyTestingApp" android:theme="@style/MainTheme">
    <receiver android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver" android:exported="false" />
    <receiver android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND">
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
            <category android:name="${applicationId}" />
        </intent-filter>
    </receiver>
</application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

MyMessagingService extending FirebaseMessagingService

[Service(Exported = false, Enabled = true, DirectBootAware =true)]
[IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })]
[IntentFilter(new[] { "com.google.firebase.INSTANCE_ID_EVENT" })]
public class MyMessagingService : FirebaseMessagingService{

}

MainActivity--> OnStart()

const int requestLocationId = 0;

string[] notiPermission =
{
    Manifest.Permission.PostNotifications
};

string[] wakePermission =
{
    Manifest.Permission.WakeLock
};

if ((int)Build.VERSION.SdkInt < 33) return;

if (activity.CheckSelfPermission(Manifest.Permission.PostNotifications) != Permission.Granted)
{
    activity.RequestPermissions(notiPermission, requestLocationId);
    activity.RequestPermissions(wakePermission, requestLocationId);
}

I have created the apk file with Sigin Identity and installed in Samsung S23. Tested with API call (Legacy) using postmen. I am getting the success response but app is not displaying anything. After open the app also not receiving any notification message.
postMan Body

{
    "to": "dpm-g36NSEaC5XFadT3ZnY:APA91bEIarlCxz6UEpyY7CYeBsnCSBpXApW6gHEOiVrvk0URkRP4FCqAHmApPFH4KQLDMfYhkkOTTUZ7ZEsRlyKzCPPS9CuLtet9pXi8_DUflE6h_g-iqtD_9DcVQ4amyb1CCfW05vN2",
    "CollapseKey": "1",    
    "data": {
        "body": "Hello,Good Morning! . Have a gr8 day ahead! message_web",
        "title": "Good Morning!)",
        "image": "https://images.pexels.com/photos/2055100/pexels-photo-2055100.jpeg",
        "notificationSmallIcon": "mk.myapp.drawable.logo",
        "notificationSmallIconColor": "#00ff00",
        "notificationLargeIcon" : "https://media.istockphoto.com/id/1352603244/photo/shot-of-an-unrecognizable-businessman-working-on-his-laptop-in-the-office.jpg?s=1024x1024&w=is&k=20&c=mTABddPRSU1r_hCBpknMjJbCIrJAicjjXGSU42rx-YI=",
        "click_action": "web",
        "actionResult": "https://google.com/"
    }
}

Additional info

Google Play Services Version 118.2.0.5

dependencies/Packages

Xamarin.AndroidX.Core 1.12.0.4
Xamarin.AndroidX.Lifecycle.Common 2.7.0.1
Xamarin.Essentials 1.7.3
Xamarin.CommunityToolkit 2.0.2
Xamarin.Firebase.Messaging 123.3.1.1
Xamarin.Forms 5.0.0.2478

Xamarin.GooglePlayServices.Base 118.0.1

Solution for : When we swipe the app to close need to receive the notification

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions