protected override void OnHandleIntent(Intent intent)
        {
            try
            {
                Bundle extras = intent.Extras;
                lock (syncLock)
                {
                    InstanceID instanceID = InstanceID.GetInstance(Android.App.Application.Context);
                    string     token      = instanceID.GetToken(CrossPushNotification.SenderId,
                                                                GoogleCloudMessaging.InstanceIdScope, null);

                    CrossPushNotification.PushNotificationListener.OnRegistered(token, DeviceType.Android);
                    PushNotificationImplementation.StoreRegistrationId(Android.App.Application.Context, token);
                    System.Diagnostics.Debug.WriteLine(string.Format("{0} - Device registered, registration ID=" + token, Tag));
                }
            }catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(string.Format("{0} - Error :" + ex.Message, Tag));

                CrossPushNotification.PushNotificationListener.OnError(string.Format("{0} - Register - " + ex.ToString(), Tag), DeviceType.Android);
            }

            // Intent registrationComplete = new Intent(PushNotificationKey.RegistrationComplete);
            // LocalBroadcastManager.GetInstance(Android.App.Application.Context).SendBroadcast(registrationComplete);
        }
Example #2
0
        /// <summary>
        /// Unregister push notifications
        /// </summary>
        public void Unregister()
        {
            System.Diagnostics.Debug.WriteLine(string.Format("{0} - Unregister -  Unregistering push notifications", PushNotificationKey.DomainName));

            InstanceID instanceID = InstanceID.GetInstance(Android.App.Application.Context);

            instanceID.DeleteToken(CrossPushNotification.SenderId, GoogleCloudMessaging.InstanceIdScope);

            CrossPushNotification.PushNotificationListener.OnUnregistered(DeviceType.Android);
            PushNotificationImplementation.StoreRegistrationId(Android.App.Application.Context, string.Empty);
        }
        /// <summary>
        /// Unregister push notifications
        /// </summary>
        public void Unregister()
        {
            ThreadPool.QueueUserWorkItem(state =>
            {
                System.Diagnostics.Debug.WriteLine(string.Format("{0} - Unregister -  Unregistering push notifications", PushNotificationKey.DomainName));
                try
                {
                    InstanceID instanceID = InstanceID.GetInstance(Android.App.Application.Context);
                    instanceID.DeleteToken(CrossPushNotification.SenderId, GoogleCloudMessaging.InstanceIdScope);

                    CrossPushNotification.PushNotificationListener.OnUnregistered(DeviceType.Android);
                    PushNotificationImplementation.StoreRegistrationId(Android.App.Application.Context, string.Empty);
                }catch (IOException ex)
                {
                    System.Diagnostics.Debug.WriteLine(string.Format("{0} - Error :" + ex.Message, Tag));

                    CrossPushNotification.PushNotificationListener.OnError(string.Format("{0} - Unregister - " + ex.ToString(), Tag), DeviceType.Android);
                }
            });
        }
Example #4
0
        protected override void OnHandleIntent(Intent intent)
        {
            try
            {
                Bundle extras = intent.Extras;
                lock (syncLock)
                {
                    InstanceID instanceID = InstanceID.GetInstance(Android.App.Application.Context);

#if _DEBUG_
                    try
                    {
                        instanceID.DeleteInstanceID();
                    }
                    catch (Exception e)
                    {
                        Android.Util.Log.Debug(Tag, e.ToString());
                    }
                    instanceID = InstanceID.GetInstance(Android.App.Application.Context);
#endif

                    string token = instanceID.GetToken(CrossPushNotification.SenderId,
                                                       GoogleCloudMessaging.InstanceIdScope, null);

                    CrossPushNotification.PushNotificationListener.OnRegistered(token, DeviceType.Android);
                    PushNotificationImplementation.StoreRegistrationId(Android.App.Application.Context, token);
                    this.SubscribeTopics(token);

                    System.Diagnostics.Debug.WriteLine($"{token} - Device registered, registration ID={Tag}");
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine($"{ex.Message} - Error : {Tag}");

                CrossPushNotification.PushNotificationListener.OnError($"{ex.ToString()} - Register - {Tag}", DeviceType.Android);
            }

            // Intent registrationComplete = new Intent(PushNotificationKey.RegistrationComplete);
            // LocalBroadcastManager.GetInstance(Android.App.Application.Context).SendBroadcast(registrationComplete);
        }