Exemple #1
0
        public override void OnMessageDelivered(string msgId, Exception exception)
        {
            // Obtain the error code and description.
            IHMSPushEvent hmsPushEvent = HMSPushEvent.Instance;

            hmsPushEvent.HMSOnMessageDelivered(msgId, ((BaseException)exception).ErrorCode, ((BaseException)exception).Message);
        }
Exemple #2
0
        public override void OnSendError(string msgId, Exception exception)
        {
            // If the sending fails, obtain the error message.
            IHMSPushEvent hmsPushEvent = HMSPushEvent.Instance;

            hmsPushEvent.HMSOnSendError(msgId, ((BaseException)exception).ErrorCode, ((BaseException)exception).Message);
        }
Exemple #3
0
        public override void OnMessageSent(string msgId)
        {
            // Obtain the message ID.
            IHMSPushEvent hmsPushEvent = HMSPushEvent.Instance;

            hmsPushEvent.HMSOnMessageSent(msgId);
        }
Exemple #4
0
        public override void OnMessageReceived(RemoteMessage message)
        {
            //It get triggered when data message comes or a notification comes which as foreground attributes false
            IHMSPushEvent hmsPushEvent = HMSPushEvent.Instance;

            hmsPushEvent.HMSOnMessageReceived(message);
        }
Exemple #5
0
        public override void OnReceive(Context context, Intent intent)
        {
            Bundle bundle = intent.Extras;

            IHMSTokenEvent hmsTokenEvent = HMSInstanceId.Instance;
            IHMSPushEvent  hmsPushEvent  = HMSPushEvent.Instance;

            if (bundle.ContainsKey(Method))
            {
                string method = intent.Extras.GetString(Method);
                if (method == ((Action <string, Bundle>)hmsTokenEvent.HMSOnNewToken).Method.Name)
                {
                    hmsTokenEvent.HMSOnNewToken(bundle.GetString(Token), bundle.GetBundle(Bundle));
                }
                else if (method == ((Action <RemoteMessage>)hmsPushEvent.HMSOnMessageReceived).Method.Name)
                {
                    hmsPushEvent.HMSOnMessageReceived(bundle.Get(Message) as RemoteMessage);
                }
                else if (method == ((Action <string>)hmsPushEvent.HMSOnMessageSent).Method.Name)
                {
                    hmsPushEvent.HMSOnMessageSent(bundle.GetString(MsgId));
                }
                else if (method == ((Action <string, int, string>)hmsPushEvent.HMSOnSendError).Method.Name)
                {
                    hmsPushEvent.HMSOnSendError(
                        bundle.GetString(MsgId),
                        bundle.GetBundle(Exception).GetInt(ErrorCode),
                        bundle.GetBundle(Exception).GetString(ErrorMessage));
                }
                else if (method == ((Action <string, int, string>)hmsPushEvent.HMSOnMessageDelivered).Method.Name)
                {
                    hmsPushEvent.HMSOnMessageDelivered(
                        bundle.GetString(MsgId),
                        bundle.GetBundle(Exception).GetInt(ErrorCode),
                        bundle.GetBundle(Exception).GetString(ErrorMessage));
                }
                else if (method == ((Action <int, string, Bundle>)hmsTokenEvent.HMSOnTokenError).Method.Name)
                {
                    hmsTokenEvent.HMSOnTokenError(
                        bundle.GetBundle(Exception).GetInt(ErrorCode),
                        bundle.GetBundle(Exception).GetString(ErrorMessage),
                        bundle.GetBundle(Bundle));
                }
            }
        }
        public MainPage()
        {
            InitializeComponent();

            hmsMessaging = DependencyService.Get <IHMSMessaging>();

            openDevice = DependencyService.Get <IOpenDevice>();

            hmsPushEvent = DependencyService.Get <IHMSPushEvent>();
            hmsPushEvent.Initialize();
            hmsPushEvent.OnMessageReceived     += OnMessageReceived;
            hmsPushEvent.OnInitialNotification += OnOpenedAppNotification;
            hmsPushEvent.OnMessageSent         += OnMessageSent;

            hmsInstanceId = DependencyService.Get <IHMSInstanceId>();
            hmsInstanceId.Initialize();
            hmsInstanceId.OnNewToken   += HMSInstanceIdOnNewToken;
            hmsInstanceId.OnTokenError += HMSInstanceIdOnTokenError;
        }