I am using PushSharp library to send Push Notification to my Xamarin.Android App. Each time while launching the app, I am checking GCM registration and if registration expires, I am sending the device token to server. Sometimes I am getting
Device Subscription Expired Exception
in log. Due to this exception my device is not receiving notification and sometimes it is getting resolved automatically and I am started receiving notification. I am not sure what is happening. How to fix this issue?
I could handle DeviceSubscriptionExcpetion as below:
gcmBroker.OnNotificationFailed += (notification, aggregateEx) =>
{
if (ex is DeviceSubscriptonExpiredException)
{
var subExc = ex as DeviceSubscriptonExpiredException;
}
}
I could delete the expired token from DB, but my confusion is actually device token is not expired. Device is valid but sometimes unable to receive notification due to this exception.
According to this thread it happens only when we have multiple registration for the same device. But I am storing device token against unique device ID. I am getting device id as below:
try
{
var telephonyManager = (TelephonyManager)Forms.Context.GetSystemService(Android.Content.Context.TelephonyService);
if (telephonyManager != null)
{
deviceId = telephonyManager.DeviceId;
if (string.IsNullOrEmpty(deviceId))
{
deviceId = Android.OS.Build.Serial;
}
}
}
Even though its said that device id is unique, but its changing most of the time. Other way I am guessing to fix this exception is by getting some ID that is always unique in Android device.
Please give some suggestion to fix this issue.