xamarin / GooglePlayServicesComponents

Other
315 stars 148 forks source link

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

Open ebinmk opened 6 months ago

ebinmk commented 6 months ago

Xamarin.Android Version (eg: 6.0):

Android 13 (API 33)

Operating System & Version (eg: Mac OSX 10.11):

Windows (development)

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

Describe your Issue

When app is in foreground/bacckground function OnMessageReceived is called. When I swipe of the app or click close all then I am not getting the notification message. I am using Data only message ,

Relevant information

Add relevant project settings from *.csproj file:

Please note I have installed Xamarin.Firebase.Messaging in Android project only

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" />

Messaging Service

[Service(Exported = false, Enabled = true, DirectBootAware =true)]
[IntentFilter(new[] { "com.google.firebase.MESSAGING_EVENT" })]
[IntentFilter(new[] { "com.google.firebase.INSTANCE_ID_EVENT" })]
public class MKMessagingService : 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);
            }

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

{
    "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": "macrokiosk.boldwallet.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://macrokiosk.com/"
    }
}

I also testing with Notification payload that time system is displaying the message with out restyling defined in OnMessageReceived. Kindly help me to identity the issue and solution