/// <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}"); } }
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); } } }
private void IsAutoInitEnabled() { var hms = HmsMessaging.GetInstance(ApplicationContext); Log.Info(TAG, "isAutoInitEnabled:" + hms.AutoInitEnabled); ShowLog("isAutoInitEnabled:" + hms?.AutoInitEnabled.ToString()); }
public void TurnOffPush() { HmsMessaging.GetInstance().TurnOffPush().AddOnSuccessListener((type) => { Debug.Log("[HMSPlugin]: TurnOffPush Complete"); }).AddOnFailureListener((exception) => { Debug.Log("[HMSPlugin]: TurnOffPush Failed" + exception.Message); }); }
/** * 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))); } }
/// <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}"); } }
/// <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}"); } }
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(); }
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); } }
/// <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}"); } }
/// <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}"); } }
public void GetAutoInitEnabled() { TestTip.Inst.ShowText($"isAutoInitEnabled: {HmsMessaging.getInstance(new Context()).isAutoInitEnabled()}"); }
public void SetAutoInitEnabled() { status = !status; HmsMessaging.getInstance(new Context()).setAutoInitEnabled(status); TestTip.Inst.ShowText(status?"ENABLED":"DISABLED"); }
public void UnSubscribeTest() { HmsMessaging.getInstance(new Context()).unsubscribe("test").addOnCompleteListener(new clistener()); }
public void TurnOn() { HmsMessaging.getInstance(new Context()).turnOnPush().addOnCompleteListener(new clistener()); }
private void IsAutoInitEnabled() { Log.Info(TAG, "isAutoInitEnabled:" + HmsMessaging.GetInstance(this).AutoInitEnabled); ShowLog("isAutoInitEnabled:" + HmsMessaging.GetInstance(this).AutoInitEnabled); }