rdelrosario / xamarin-plugins

Cross platform Xamarin & Windows plugins for PCLs
MIT License
179 stars 161 forks source link

Notification only works on the very first Android install in debug mode? #89

Open jelmarlaunchlabs opened 7 years ago

jelmarlaunchlabs commented 7 years ago

I've tried this:

  1. Debug using a device.
  2. Start debugging the app push notification works fine (at first).
  3. Stop the debugging.
  4. Start the debugging again, now push notification does not work anymore, up until app is uninstalled the start the steps written here.

issue only on Android.

bassie1978 commented 7 years ago

I have exactly the same problem...

rdelrosario commented 7 years ago

On Release you shouldn't have this issue. The problem is on debug Android removes and installs the app again.

On Tue, Sep 27, 2016 at 5:12 AM, pug205 notifications@github.com wrote:

I have exactly the same problem...

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/rdelrosario/xamarin-plugins/issues/89#issuecomment-249810067, or mute the thread https://github.com/notifications/unsubscribe-auth/ACbgJzxmDaPQks9OaAEHX2M_8tFhdz4Rks5quN3tgaJpZM4KCkE7 .

vhendriks81 commented 7 years ago

If it was removing and re-installing then all preferences etc would have been erased. This isn't the case..

Do you have any idea why this is happening other than "because Android removes and installs the app again"?

jelmarlaunchlabs commented 7 years ago

Yes I've noticed that too, my caches and setting are all preserved when the debugging is restarted and usually it will only be erased when I manually installing and reinstalling the app, something is missing here.

bassie1978 commented 7 years ago

I can reproduce the problem even when I'm not debugging. When I deploy a debug build when the app is not installed on the device, push works. When I force stop the app and start it again, push still works. When I redeploy the app, push no longer works. I was using GCM and I tested against firebase just now, with the same results.

bassie1978 commented 7 years ago

I did some research on Google and found the following thread on the Xamarin forum: https://forums.xamarin.com/discussion/62810/xamarin-android-gcm-notification

"I had also the same issue and started to investigate it. Seems that when you debug deploy again with the same app version, the instanceId isn't valid anymore but gcm doesn't seem to notice this and the token remains the same. When you toggle the appversion (either up or down) everything seems to work fine."

And a code example [...] var instanceID = InstanceID.GetInstance (Android.App.Application.Context); // inital call, will maybe get old instanceID instanceID.DeleteInstanceID (); // force unregistration instanceID = InstanceID.GetInstance (Android.App.Application.Context); // get a new one var token = instanceID.GetToken([...])

rdelrosario commented 7 years ago

Hey @pug205

Could you do a PR with this I will merge it once tested.

ShahriatHossain commented 7 years ago

@pug205 I also have the same problem and sorted out the problem again generating the token on my demo project following this tutorial https://developer.xamarin.com/guides/android/application_fundamentals/notifications/remote_notifications_in_android/

but in this xamarin plugin how can I fix this problem, where I can get the code to regenerate the token again?

jelmarlaunchlabs commented 7 years ago

Any updates on this? This problem seems lurking for a while now.

rdelrosario commented 7 years ago

Should be fixed on:

https://www.nuget.org/packages/Xam.Plugin.PushNotification/1.2.5-beta