Example #1
0
        /*
         * GetToken(String appId, String scope), This method is used to obtain a token required for accessing HUAWEI Push Kit.
         * If there is no local AAID, this method will automatically generate an AAID when it is called because the Huawei Push server needs to generate a token based on the AAID.
         * This method is a synchronous method, and you cannot call it in the main thread. Otherwise, the main thread may be blocked.
         */
        private void GetToken()
        {
            ShowLog("getToken:begin");

            System.Threading.Thread thread = new System.Threading.Thread(() =>
            {
                try
                {
                    string appid = AGConnectServicesConfig.FromContext(this).GetString("client/app_id");
                    string token = HmsInstanceId.GetInstance(this).GetToken(appid, "HCM");
                    Log.Info(TAG, "token = " + token);

                    if (!TextUtils.IsEmpty(token))
                    {
                        SendRegTokenToServer(token);
                    }

                    ShowLog("get token:" + token);
                }
                catch (Exception e)
                {
                    Log.Info(TAG, e.ToString());
                    ShowLog("get token failed, " + e);
                }
            }

                                                                         );
            Log.Info(TAG, "start the thread");
            thread.Start();
        }
Example #2
0
    void Start()
    {
        Debug.Log("AppMessaging: Start");

        HmsInstanceId      inst     = HmsInstanceId.GetInstance();
        ITask <AAIDResult> idResult = inst.AAID;

        idResult.AddOnSuccessListener((result) =>
        {
            AAIDResult AAIDResult = result;
            Debug.Log("AppMessaging: " + result.Id);
            AAIDResultAction?.Invoke(result);
        }).AddOnFailureListener((exception) =>
        {
        });
        OnMessageClicked  = OnMessageClickFunction;
        OnMessageDisplay  = OnMessageDisplayFunction;
        OnMessageDissmiss = OnMessageDissmissFunction;
        AGConnectAppMessaging appMessaging = AGConnectAppMessaging.Instance;

        appMessaging.AddOnClickListener(OnMessageClicked);
        appMessaging.AddOnDisplayListener(OnMessageDisplay);
        appMessaging.AddOnDismissListener(OnMessageDissmiss);
        appMessaging.SetForceFetch();
    }
Example #3
0
        /**
         * GetAAID(), This method is used to obtain an AAID in asynchronous mode. You need to add a listener to listen to the operation result.
         * DeleteAAID(), delete a local AAID and its generation timestamp.
         * @param isGet getAAID or deleteAAID
         */

        private void SetAAID(bool isGet)
        {
            /**
             * isGet seperates getAAID or DeleteAAID
             */
            if (isGet)
            {
                // Get AAID
                Log.Info(TAG, "Starting AAID");
                Task idResult = HmsInstanceId.GetInstance(this).AAID;
                idResult.AddOnSuccessListener(new OnSuccessListenerImp(handler, DELETE_AAID, this)).AddOnFailureListener(new OnFailureListenerImp(this));
            }
            else
            {
                // DELETE AAID
                System.Threading.Thread thread = new System.Threading.Thread(() =>
                {
                    try
                    {
                        HmsInstanceId.GetInstance(this).DeleteAAID();
                        Log.Info(TAG, "AAID deleted");
                        ShowLog("delete aaid and its generation timestamp success.");
                        handler.SendEmptyMessage(GET_AAID);
                    }
                    catch (Exception e)
                    {
                        Log.Error(TAG, "deleteAAID failed" + e.ToString());
                        ShowLog("delete failed.");
                    }
                });

                Log.Info(TAG, "start the thread");
                thread.Start();
            }
        }
Example #4
0
        public void GetToken()
        {
            string appId = AGConnectServicesConfig.fromContext(new Context()).getString("client/app_id");
            string token = HmsInstanceId.getInstance(new Context()).getToken(appId, "HCM");

            TestTip.Inst.ShowText(token);
            GUIUtility.systemCopyBuffer = token;
        }
Example #5
0
        /// <summary>
        /// Obtains an AAID in synchronous mode.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnClickGetId(object sender, EventArgs e)
        {
            string MethodName = "Id";

            try
            {
                string Id = HmsInstanceId.GetInstance(this).Id;
                log.Info(MethodName, Id);
            }
            catch (Exception exception)
            {
                log.Error(MethodName, $"Error/Exception: {exception.Message}");
            }
        }
Example #6
0
        /// <summary>
        /// Obtains the generation timestamp of an AAID.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnClickCreationTime(object sender, EventArgs e)
        {
            string MethodName = "CreationTime";

            try
            {
                long creationTime = HmsInstanceId.GetInstance(this).CreationTime;
                log.Info(MethodName, creationTime);
            }
            catch (Exception exception)
            {
                log.Error(MethodName, $"Error/Exception: {exception.Message}");
            }
        }
        public async void GetAAID()
        {
            HmsInstanceId     hmsInstanceId = HmsInstanceId.GetInstance(this);
            Task <AAIDResult> idTask        = hmsInstanceId.GetAAIDAsync();
            var result = await idTask;

            if (idTask.IsCompleted && idTask.Result != null)
            {
                txtResult.Text = "Your Id: " + result.Id;
                Console.WriteLine("AAID retrieved successfully: " + result.Id);
            }
            else
            {
                Console.WriteLine("AAID retrieved failed: " + idTask.Result);
            }
        }
Example #8
0
        /// <summary>
        /// Deletes a local AAID and its generation timestamp.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnClickDeleteAAID(object sender, EventArgs e)
        {
            string MethodName = "DeleteAAID";
            Thread thread     = new Thread(() =>
            {
                try
                {
                    HmsInstanceId.GetInstance(this).DeleteAAID();
                    log.Info(MethodName, "Success");
                }
                catch (Exception exception)
                {
                    log.Error(MethodName, $"Error/Exception: {exception.Message}");
                }
            });

            thread.Start();
        }
Example #9
0
 private void GetToken()
 {
     System.Threading.Thread thread = new System.Threading.Thread(() =>
     {
         try
         {
             string appid = AGConnectServicesConfig.FromContext(this).GetString("client/app_id");
             string token = HmsInstanceId.GetInstance(this).GetToken(appid, "HCM");
             Log.Info(TAG, "token = " + token);
         }
         catch (Java.Lang.Exception e)
         {
             Log.Info(TAG, e.ToString());
         }
     }
                                                                  );
     Log.Info(TAG, "start the thread");
     thread.Start();
 }
Example #10
0
        /// <summary>
        /// Obtains a token required for accessing Push Kit.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnClickGetToken(object sender, EventArgs e)
        {
            string MethodName = "GetToken";
            Thread thread     = new Thread(() =>
            {
                try
                {
                    string appid = AGConnectServicesConfig.FromContext(this).GetString("client/app_id");
                    string token = HmsInstanceId.GetInstance(this).GetToken(appid, HmsMessaging.DefaultTokenScope);

                    log.Info(MethodName, token);
                }
                catch (ApiException exception)
                {
                    log.Error(MethodName, $"Error/Exception: {exception.Message}");
                }
            });

            thread.Start();
        }
Example #11
0
 /**
  * void DeleteToken(String appId, String scope) throws ApiException
  * This method is used to obtain a token. After a token is deleted, the corresponding AAID will not be deleted.
  * This method is a synchronous method. Do not call it in the main thread. Otherwise, the main thread may be blocked.
  */
 private void DeleteToken()
 {
     ShowLog("deleteToken:begin");
     System.Threading.Thread thread = new System.Threading.Thread(() =>
     {
         try
         {
             string appid = AGConnectServicesConfig.FromContext(this).GetString("client/app_id");
             HmsInstanceId.GetInstance(this).DeleteToken(appid, "HCM");
             Log.Info(TAG, "deleteToken success.");
             ShowLog("deleteToken success");
         }
         catch (ApiException e)
         {
             Log.Error(TAG, "deleteToken failed." + e);
             ShowLog("deleteToken failed." + e);
         }
     });
     Log.Info(TAG, "start the thread");
     thread.Start();
 }
Example #12
0
        /// <summary>
        /// Obtains an AAID in asynchronous mode.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void OnClickGetAAID(object sender, EventArgs e)
        {
            string MethodName = "GetAAID";
            var    task       = HmsInstanceId.GetInstance(this).GetAAIDAsync();

            try
            {
                await task;
                if (task.IsCompleted)
                {
                    AAIDResult aaid = task.Result;
                    log.Info(MethodName, $"{aaid.Id}");
                }
                else
                {
                    var exception = task.Exception;
                    log.Error(MethodName, $"Error/Exception: {exception.Message}");
                }
            }
            catch (Exception exception)
            {
                log.Error(MethodName, $"Error/Exception: {exception.Message}");
            }
        }
Example #13
0
 public void SetAAID(bool isGet)
 {
     if (isGet)
     {
         Task id = HmsInstanceId.getInstance(new Context()).getAAID();
         id.addOnSuccessListener(new HmsSuccessListener <AAIDResult>((aaidResult) =>
         {
             String aaId = aaidResult.getId();
             TestTip.Inst.ShowText("getAAID success:" + aaId);
         })).addOnFailureListener(new HmsFailureListener((e) =>
         {
             TestTip.Inst.ShowText($"getAAID failed: {e.toString()}");
         }));
     }
     else
     {
         try {
             HmsInstanceId.getInstance(new Context()).deleteAAID();
             TestTip.Inst.ShowText("delete aaid and its generation timestamp success.");
         } catch (System.Exception e) {
             TestTip.Inst.ShowText("deleteAAID failed. " + e);
         }
     }
 }
 public void DeleteToken()
 {
     HmsInstanceId.GetInstance().DeleteToken(MetadataHelper.AppId, HmsMessaging.DEFAULT_TOKEN_SCOPE);
 }
Example #15
0
        public void DeleteToken()
        {
            string appId = AGConnectServicesConfig.fromContext(new Context()).getString("client/app_id");

            HmsInstanceId.getInstance(new Context()).deleteToken(appId, "HCM");
        }
Example #16
0
 public void Initialize()
 {
     Instance = this;
     Client   = HmsInstanceId.GetInstance(Application.Context);
 }