Exemplo n.º 1
0
        /// <summary>
        /// Sends uplink messages in asynchronous mode.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnClickSendRemoteMessage(object sender, EventArgs e)
        {
            string Tag       = "SendRemoteMessage";
            Random rnd       = new Random();
            string messageId = rnd.Next().ToString();
            Dictionary <string, string> data = new Dictionary <string, string>
            {
                ["key1"]    = "test",
                ["message"] = "huawei-test",
            };

            // The input parameter of the RemoteMessage.Builder method is push.hcm.upstream, which cannot be changed.
            RemoteMessage.Builder builder = new RemoteMessage.Builder("push.hcm.upstream")
                                            .SetCollapseKey("-1")
                                            .SetMessageId(messageId)
                                            .SetMessageType("hms")
                                            .SetTtl(120)
                                            .SetData(data)
                                            .SetSendMode(1)
                                            .SetReceiptMode(1);

            RemoteMessage message = builder.Build();

            try
            {
                //Get Token before send RemoteMessage
                HmsMessaging.GetInstance(this).Send(message);
            }
            catch (ApiException exception)
            {
                log.Error(Tag, $"Error/Exception: {exception.Message}");
            }
        }
Exemplo n.º 2
0
 public void OnConfirmClick(string msg)
 {
     if (actionType == 1)
     {
         topicDialog.Dismiss();
         try
         {
             HmsMessaging.GetInstance(mainActivity)
             .Subscribe(msg)
             .AddOnCompleteListener(new OnCompleteListenerMessagingImp(0, mainActivity));
         }
         catch (Exception e)
         {
             mainActivity.ShowLog("subscribe failed: exception=" + e.Message);
             Log.Error(TAG, "subscribe failed: exception=" + e);
         }
     }
     else
     {
         topicDialog.Dismiss();
         try
         {
             HmsMessaging.GetInstance(mainActivity)
             .Unsubscribe(msg)
             .AddOnCompleteListener(new OnCompleteListenerMessagingImp(1, mainActivity));
         }
         catch (Exception e)
         {
             mainActivity.ShowLog("unsubscribe failed: exception=" + e.Message);
             Log.Error(TAG, "unsubscribe failed: exception=" + e);
         }
     }
 }
Exemplo n.º 3
0
        private void IsAutoInitEnabled()
        {
            var hms = HmsMessaging.GetInstance(ApplicationContext);

            Log.Info(TAG, "isAutoInitEnabled:" + hms.AutoInitEnabled);
            ShowLog("isAutoInitEnabled:" + hms?.AutoInitEnabled.ToString());
        }
Exemplo n.º 4
0
 public void TurnOffPush()
 {
     HmsMessaging.GetInstance().TurnOffPush().AddOnSuccessListener((type) =>
     {
         Debug.Log("[HMSPlugin]: TurnOffPush Complete");
     }).AddOnFailureListener((exception) =>
     {
         Debug.Log("[HMSPlugin]: TurnOffPush Failed" + exception.Message);
     });
 }
Exemplo n.º 5
0
        /**
         * Set up enable or disable the display of notification messages.
         * @param enable enabled or not
         */

        private void SetReceiveNotifyMsg(bool enable)
        {
            ShowLog("Control the display of notification messages:begin");
            if (enable)
            {
                HmsMessaging.GetInstance(this).TurnOnPush().AddOnCompleteListener(new OnCompleteListenerImp(tvSetPush, this, Resources.GetString(Resource.String.set_push_unable)));
            }
            else
            {
                HmsMessaging.GetInstance(this).TurnOffPush().AddOnCompleteListener(new OnCompleteListenerFailImp(tvSetPush, this, Resources.GetString(Resource.String.set_push_enable)));
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Checks whether automatic initialization is enabled.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnClickIsAutoInitEnabled(object sender, EventArgs e)
        {
            string MethodName = "IsAutoInitEnabled";

            try
            {
                bool isAutoInitEnabled = HmsMessaging.GetInstance(this).AutoInitEnabled;
                log.Info(MethodName, isAutoInitEnabled);
            }
            catch (Exception exception)
            {
                log.Error(MethodName, $"Error/Exception: {exception.Message}");
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// disable automatic initialization
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnClickDisableAutoInit(object sender, EventArgs e)
        {
            string MethodName = "DisableAutoInit";

            try
            {
                HmsMessaging.GetInstance(this).AutoInitEnabled = false;
                log.Info(MethodName, "Success");
            }
            catch (Exception exception)
            {
                log.Error(MethodName, $"Error/Exception: {exception.Message}");
            }
        }
Exemplo n.º 8
0
        public void SendMessage()
        {
            string        messageId     = DateTime.Now.Millisecond.ToString();
            RemoteMessage remoteMessage = new RemoteMessage.Builder("push.hcm.upstream")
                                          .setMessageId(messageId)
                                          .addData("key1", "data1")
                                          .addData("key2", "data2")
                                          .build();

            try {
                HmsMessaging.getInstance(new Context()).send(remoteMessage);
                TestTip.Inst.ShowText("sending...");
            } catch (System.Exception e) {
                TestTip.Inst.ShowText("send exception:" + e);
            }
        }
        private void OnPushButtonClicked(object sender, EventArgs e)
        {
            var instance = HmsMessaging.GetInstance(ApplicationContext);

            instance.AutoInitEnabled = true;
            SendEvent("Tap", "Push");
            var token = Xamarin.Essentials.Preferences.Get("PushToken", string.Empty);

            ClipboardManager clipboard = (ClipboardManager)GetSystemService(Context.ClipboardService);
            ClipData         clip      = ClipData.NewPlainText("Push Token", token);

            clipboard.PrimaryClip = clip;

            Log.Info(TAG, $"Push token: {token}");
            Toast.MakeText(this, $"Push token: {token} added to clipboard", ToastLength.Short).Show();
        }
Exemplo n.º 10
0
 private void SetAutoInitEnabled(bool enable)
 {
     if (enable)
     {
         HmsMessaging.GetInstance(this).AutoInitEnabled = true;
         Log.Info(TAG, "setAutoInitEnabled: true");
         ShowLog("setAutoInitEnabled: true");
         tvSetAutoInit.Text = Resources.GetString(Resource.String.AutoInitDisabled);
     }
     else
     {
         HmsMessaging.GetInstance(this).AutoInitEnabled = false;
         Log.Info(TAG, "setAutoInitEnabled: false");
         ShowLog("setAutoInitEnabled: false");
         tvSetAutoInit.Text = Resources.GetString(Resource.String.AutoInitEnabled);
     }
 }
Exemplo n.º 11
0
        /// <summary>
        /// Enables the function of receiving notification messages in asynchronous mode.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void OnClickTurnOnPush(object sender, EventArgs e)
        {
            string MethodName = "TurnOnPush";
            var    task       = HmsMessaging.GetInstance(this).TurnOnPushAsync();

            try
            {
                await task;
                if (task.IsCompleted)
                {
                    log.Info(MethodName, $"Success");
                }
                else
                {
                    var exception = task.Exception;
                    log.Error(MethodName, $"Error/Exception: {exception.Message}");
                }
            }
            catch (Exception exception)
            {
                log.Error(MethodName, $"Error/Exception: {exception.Message}");
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Subscribes to topics in asynchronous mode.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void OnClickSubscribe(object sender, EventArgs e)
        {
            string MethodName = "Subscribe";
            string topic      = txtTopic.Text;
            var    task       = HmsMessaging.GetInstance(this).SubscribeAsync(topic);

            try
            {
                await task;
                if (task.IsCompleted)
                {
                    log.Info(MethodName, $"Success");
                }
                else
                {
                    var exception = task.Exception;
                    log.Error(MethodName, $"Error/Exception: {exception.Message}");
                }
            }
            catch (Exception exception)
            {
                log.Error(MethodName, $"Error/Exception: {exception.Message}");
            }
        }
Exemplo n.º 13
0
 public void GetAutoInitEnabled()
 {
     TestTip.Inst.ShowText($"isAutoInitEnabled: {HmsMessaging.getInstance(new Context()).isAutoInitEnabled()}");
 }
Exemplo n.º 14
0
 public void SetAutoInitEnabled()
 {
     status = !status;
     HmsMessaging.getInstance(new Context()).setAutoInitEnabled(status);
     TestTip.Inst.ShowText(status?"ENABLED":"DISABLED");
 }
Exemplo n.º 15
0
 public void UnSubscribeTest()
 {
     HmsMessaging.getInstance(new Context()).unsubscribe("test").addOnCompleteListener(new clistener());
 }
Exemplo n.º 16
0
 public void TurnOn()
 {
     HmsMessaging.getInstance(new Context()).turnOnPush().addOnCompleteListener(new clistener());
 }
Exemplo n.º 17
0
 private void IsAutoInitEnabled()
 {
     Log.Info(TAG, "isAutoInitEnabled:" + HmsMessaging.GetInstance(this).AutoInitEnabled);
     ShowLog("isAutoInitEnabled:" + HmsMessaging.GetInstance(this).AutoInitEnabled);
 }