Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android: Notification not working when app killed from background and again open #153

Open
fazil1979 opened this issue Nov 7, 2020 · 2 comments

Comments

@fazil1979
Copy link

It works like this:

  • it works if app is in foreground or background,
  • if kill app and then send notification it not works
  • if you again open app and it's again either in background or foreground notifications not come
@jbtdevgit
Copy link

jbtdevgit commented Nov 18, 2020

Try doing the solution here #33

An update:

Plugin.PushNotification 3.3.3
Xamarin.Firebase.Messaging 120.1.7
Xamarin.GooglePlayServices.Basement 117.2.1
Xamarin.Google.PlayServices.Tasks 117.2.1

Manifest:

<uses-permission android:name="android.permission.WAKE_LOCK" />
   <uses-permission android:name="android.permission.INTERNET" />
   <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver" android:exported="false" />
    <meta-data android:name="firebase_analytics_collection_enabled" android:value="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="{packageName}" />
      </intent-filter>
    </receiver>

Application Class:

public override void OnCreate()
        {
            base.OnCreate();
            if (Build.VERSION.SdkInt < BuildVersionCodes.O)
            {
                return;
            }
            PushNotificationManager.DefaultNotificationChannelImportance = NotificationImportance.High;
            PushNotificationManager.Initialize(this, resetToken: true);
        }

Initialisation is made on Application Class
Close App:
Send first notification = Success
Succeeding notifications = Fail

Open App:
Send notification = Fail

Close the app and open it again, notifications are received.

This is a weird behaviour.

@jbtdevgit
Copy link

jbtdevgit commented Nov 19, 2020

I've managed to track down the bug, but need confirmation to the plugin owners.

During debug the variable reset token invalidates the registration whenever you kill the app, so you have to open/close/open again for the notification works.
PushNotificationManager.Initialize(this, new yourCustomPushHandler(), resetToken: true);

Error in. azure when resetToken is true after closing the application:

The Notification was successfully sent to the Push Notification System
gcm
The Push Notification System handle for the registration is no longer valid

This can be reproduced easily with a blank application along with azure hub notifications.

So the fix is to set the reset token to false or create a configuration where you should apply the resetToken to true or false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants