public void Authenticate(Action <AuthServiceResult> callback) { if (!m_initialized) { Debug.Log("AppGalleryService -> CreateAuthParams"); var authParams = new HuaweiIdAuthParamsHelper(HuaweiIdAuthParams.DEFAULT_AUTH_REQUEST_PARAM_GAME).SetIdToken().SetAccessToken().CreateParams(); Debug.Log("AppGalleryService -> GetService"); m_authService = HuaweiIdAuthManager.GetService(authParams); m_initialized = true; } Debug.Log("AppGalleryService -> Start SignOut"); var signOut = m_authService.SignOut(); signOut.AddOnSuccessListener(success => { Debug.Log($"AppGalleryService -> SignOut Success"); SignIn(callback); }); signOut.AddOnFailureListener(error => { Debug.Log($"AppGalleryService -> SignOut Error {error.Message}"); SignIn(callback); }); }
protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data) { base.OnActivityResult(requestCode, resultCode, data); Logger.Info(Tag, "onActivityResult, requestCode = " + requestCode + ", resultCode = " + resultCode); try { // Handle HMS SDK authentication sign in callback results if (requestCode == HmsProxyImpl.REQUEST_SIGN_IN_LOGIN) { // login success, get user message by getSignedInAccountFromIntent Task authHuaweiIdTask = HuaweiIdAuthManager.ParseAuthResultFromIntent(data); if (authHuaweiIdTask.IsSuccessful) { AuthHuaweiId huaweiAccount = (AuthHuaweiId)authHuaweiIdTask.Result; Logger.Info(Tag, "onActivityResult, signIn success " + huaweiAccount.DisplayName); HmsProxyImpl.Instance.DealSignInResult(huaweiAccount); InitDrive(); } else { // login failed Logger.Info(Tag, "onActivityResult, signIn failed: " + ((ApiException)authHuaweiIdTask.Exception).StatusCode); Toast.MakeText(ApplicationContext, "onActivityResult, signIn failed.", ToastLength.Long).Show(); } } } catch (Exception e) { Logger.Info(Tag, "onActivityResult, catch Exception"); } }
private void InitAutoRecorderController() { HiHealthOptions hiHealthOptions = HiHealthOptions.HiHealthOptionsBulider().Build(); AuthHuaweiId signInHuaweiId = HuaweiIdAuthManager.GetExtendedAuthResult(hiHealthOptions); MyAutoRecorderController = HuaweiHiHealth.GetAutoRecorderController(this, signInHuaweiId); }
// Check the connectivity private void CheckConnect() { if (MyActivityRecordsController == null) { HiHealthOptions hiHealthOptions = HiHealthOptions.HiHealthOptionsBulider().Build(); AuthHuaweiId signInHuaweiId = HuaweiIdAuthManager.GetExtendedAuthResult(hiHealthOptions); MyActivityRecordsController = HuaweiHiHealth.GetActivityRecordsController(this, signInHuaweiId); } }
protected override void OnActivityResult(int requestCode, Android.App.Result resultCode, Intent data) { base.OnActivityResult(requestCode, resultCode, data); HiHealthOptions hiHealthOptions = HiHealthOptions.HiHealthOptionsBulider().Build(); AuthHuaweiId signInHuaweiId = HuaweiIdAuthManager.GetExtendedAuthResult(hiHealthOptions); MyAutoRecorderController = HuaweiHiHealth.GetAutoRecorderController(this, signInHuaweiId); }
private void InitService() { Log.Info(TAG, "HiHealthKitClient connect to service"); // Initialize SettingController HiHealthOptions fitnessOptions = HiHealthOptions.HiHealthOptionsBulider().Build(); AuthHuaweiId signInHuaweiId = HuaweiIdAuthManager.GetExtendedAuthResult(fitnessOptions); MySettingController = HuaweiHiHealth.GetSettingController(this, signInHuaweiId); }
private void InitSettingController() { // create HiHealth Options, donnot add any datatype here. HiHealthOptions hiHealthOptions = HiHealthOptions.HiHealthOptionsBulider().Build(); // get AuthHuaweiId by HiHealth Options. AuthHuaweiId signInHuaweiId = HuaweiIdAuthManager.GetExtendedAuthResult(hiHealthOptions); MySettingController = HuaweiHiHealth.GetSettingController(this, signInHuaweiId); }
/// <summary> /// Huawei Api Client authorized login method /// </summary> /// <param name="activity">Call the Activity page handle of the singIn interface</param> public void SingIn(Activity activity) { if (authParams == null) { authParams = InitData(); } service = HuaweiIdAuthManager.GetService(activity, authParams); activity.StartActivityForResult(service.SignInIntent, REQUEST_SIGN_IN_LOGIN); }
//Initiate BleController private void InitBLEController() { if (MyBleController == null) { HiHealthOptions hiHealthOptions = HiHealthOptions.HiHealthOptionsBulider().Build(); AuthHuaweiId signInHuaweiId = HuaweiIdAuthManager.GetExtendedAuthResult(hiHealthOptions); MyBleController = HuaweiHiHealth.GetBleController(this, signInHuaweiId); } }
private void InitHuaweiAuthService() { if (_authService == null) { var authParams = new HuaweiIdAuthParamsHelper(HuaweiIdAuthParams.DEFAULT_AUTH_REQUEST_PARAM_GAME).SetIdToken().CreateParams(); _authService = HuaweiIdAuthManager.GetService(authParams); Debug.Log(TAG + " authservice is assigned."); } }
/// <summary> /// Signing In with HUAWEI ID (Authorization Code) /// </summary> private void SignInCode() { authParam = new HuaweiIdAuthParamsHelper(HuaweiIdAuthParams.DefaultAuthRequestParam) .SetProfile() .SetAuthorizationCode() .CreateParams(); authManager = HuaweiIdAuthManager.GetService(this, authParam); StartActivityForResult(authManager.SignInIntent, Constant.RequestSignInLoginCode); }
/// <summary> /// Signing In with HUAWEI ID (ID Token) /// </summary> private void SignIn() { authParam = new HuaweiIdAuthParamsHelper(HuaweiIdAuthParams.DefaultAuthRequestParam) .SetIdToken() .SetAccessToken() .CreateParams(); authManager = HuaweiIdAuthManager.GetService(this, authParam); StartActivityForResult(authManager.SignInIntent, Constant.RequestSignInLogin); }
private void FabOnClick(object sender, EventArgs eventArgs) { //View view = (View) sender; //Snackbar.Make(view, "Replace with your own action", Snackbar.LengthLong) // .SetAction("Action", (Android.Views.View.IOnClickListener)null).Show(); HuaweiIdAuthParams authParams = new HuaweiIdAuthParamsHelper(HuaweiIdAuthParams.DefaultAuthRequestParam).SetIdToken().CreateParams(); IHuaweiIdAuthService service = HuaweiIdAuthManager.GetService(this, authParams); StartActivityForResult(service.SignInIntent, 8888); }
private void ImgHuaweiId_Click(object sender, EventArgs e) { HuaweiIdAuthParamsHelper huaweiIdAuthParamsHelper = new HuaweiIdAuthParamsHelper(HuaweiIdAuthParams.DefaultAuthRequestParam); List <Scope> scopeList = new List <Scope>(); scopeList.Add(new Scope(HwIDConstant.SCOPE.AccountBaseprofile)); huaweiIdAuthParamsHelper.SetScopeList(scopeList); HuaweiIdAuthParams authParams = huaweiIdAuthParamsHelper.SetAccessToken().CreateParams(); IHuaweiIdAuthService service = HuaweiIdAuthManager.GetService(this, authParams); StartActivityForResult(service.SignInIntent, SignCode); }
private void checkIapAvailabity() { iapClient = Iap.GetIapClient(); ITask <EnvReadyResult> task = iapClient.EnvReady; task.AddOnSuccessListener((result) => { Debug.Log("HMSP: checkIapAvailabity SUCCESS"); InitIAP(); }).AddOnFailureListener((exception) => { Debug.Log("HMSP: Error on ObtainOwnedPurchases"); if (IapApiExceptionUtils.IsIapApiException(exception)) { IapApiException iapApiException = IapApiExceptionUtils.AsIapApiException((exception)); Status status = iapApiException.Status; if (status.StatusCode == OrderStatusCode.ORDER_HWID_NOT_LOGIN) { // User not logged in if (status.HasResolution()) { status.StartResolutionForResult((androidIntent) => { Debug.Log("[HMS]: IAP login intent launched"); ITask <AuthHuaweiId> authTask = HuaweiIdAuthManager.ParseAuthResultFromIntent(androidIntent); authTask.AddOnSuccessListener((result) => { Debug.Log("[HMS]: IAP logged in user:"******"[HMS]: IAP user not logged:" + authException.Message); }); }, (statusException) => { Debug.Log("[HMS]: IAP login intent ERROR"); }); } } else if (status.StatusCode == OrderStatusCode.ORDER_ACCOUNT_AREA_NOT_SUPPORTED) { // The current region does not support HUAWEI IAP. Debug.Log("[HMS]: USer Area not supported by Huawei IAP"); } } }); }
private void InitDataController() { // Obtain and set the read & write permissions for DtContinuousStepsDelta and DtInstantaneousHeight. // Use the obtained permissions to obtain the data controller object. HiHealthOptions hiHealthOptions = HiHealthOptions.HiHealthOptionsBulider() .AddDataType(DataType.DtContinuousStepsDelta, HiHealthOptions.AccessRead) .AddDataType(DataType.DtContinuousStepsDelta, HiHealthOptions.AccessWrite) .AddDataType(DataType.DtInstantaneousHeight, HiHealthOptions.AccessRead) .AddDataType(DataType.DtInstantaneousHeight, HiHealthOptions.AccessWrite) .Build(); AuthHuaweiId signInHuaweiId = HuaweiIdAuthManager.GetExtendedAuthResult(hiHealthOptions); MyDataController = HuaweiHiHealth.GetDataController(this, signInHuaweiId); }
public async void StopRecordByType() { Logger("StopRecordByType"); if (MyAutoRecorderController == null) { HiHealthOptions hiHealthOptions = HiHealthOptions.HiHealthOptionsBulider().Build(); AuthHuaweiId signInHuaweiId = HuaweiIdAuthManager.GetExtendedAuthResult(hiHealthOptions); MyAutoRecorderController = HuaweiHiHealth.GetAutoRecorderController(this, signInHuaweiId); } Task StopTask = MyAutoRecorderController.StopRecordAsync(Huawei.Hms.Hihealth.Data.DataType.DtContinuousStepsTotal, new MySamplePointListener()); try { await StopTask; if (StopTask.IsCompleted) { if (StopTask.Exception == null) { Logger("StopRecordByType Successful"); Logger(Split); } else { Logger("StopRecordByType Failed: " + StopTask.Exception); Logger(Split); } } } catch (System.Exception ex) { Logger("StopRecordByType Failed: " + ex.Message); Logger(Split); } if (Count > 0) { StopService(intent); this.UnregisterReceiver(Receiver); Count--; } }
protected override void OnActivityResult(int requestCode, [GeneratedEnum] Result resultCode, Intent data) { base.OnActivityResult(requestCode, resultCode, data); if (requestCode == 8888) { var authHuaweiIdTask = HuaweiIdAuthManager.ParseAuthResultFromIntent(data); if (authHuaweiIdTask.IsSuccessful) { //The sign-in is successful, and the user's HUAWEI ID information and ID token are obtained. AuthHuaweiId huaweiAccount = authHuaweiIdTask.GetResult <AuthHuaweiId>(); Log.Info(TAG, "idToken:" + huaweiAccount.IdToken); } else { //The sign-in failed. Log.Error(TAG, "sign in failed : " + ((ApiException)authHuaweiIdTask.Exception).StatusCode); } } }
protected override void OnActivityResult(int requestCode, Result resultCode, Intent data) { base.OnActivityResult(requestCode, resultCode, data); if (requestCode == Constant.RequestSignInLogin) { //login success //get user message by ParseAuthResultFromIntent Task authHuaweiIdTask = HuaweiIdAuthManager.ParseAuthResultFromIntent(data); if (authHuaweiIdTask.IsSuccessful) { AuthHuaweiId huaweiAccount = (AuthHuaweiId)authHuaweiIdTask.Result; Log.InfoFunc(TAG, huaweiAccount.DisplayName + " signIn success "); Log.InfoFunc(TAG, "AccessToken: " + huaweiAccount.AccessToken); ValidateIdToken(huaweiAccount.IdToken); } else { Log.InfoFunc(TAG, "signIn failed: " + (authHuaweiIdTask.Exception).ToString()); } } if (requestCode == Constant.RequestSignInLoginCode) { //login success Task authHuaweiIdTask = HuaweiIdAuthManager.ParseAuthResultFromIntent(data); if (authHuaweiIdTask.IsSuccessful) { AuthHuaweiId huaweiAccount = (AuthHuaweiId)authHuaweiIdTask.Result; Log.InfoFunc(TAG, "signIn get code success."); Log.InfoFunc(TAG, "ServerAuthCode: " + huaweiAccount.AuthorizationCode); /**** english doc:For security reasons, the operation of changing the code to an AT must be performed on your server. The code is only an example and cannot be run. ****/ /**********************************************************************************************/ } else { Log.InfoFunc(TAG, "signIn get code failed: " + (authHuaweiIdTask.Exception).ToString()); } } }
private void Init() { HiHealthOptions hiHealthOptions = HiHealthOptions.HiHealthOptionsBulider().Build(); AuthHuaweiId signInHuaweiId = HuaweiIdAuthManager.GetExtendedAuthResult(hiHealthOptions); MyActivityRecordsController = HuaweiHiHealth.GetActivityRecordsController(this, signInHuaweiId); MyDataController = HuaweiHiHealth.GetDataController(this, signInHuaweiId); LogInfoView = (TextView)FindViewById(Resource.Id.activity_records_controller_log_info); LogInfoView.MovementMethod = ScrollingMovementMethod.Instance; BeginActivity = (Button)FindViewById(Resource.Id.records_controller_begin_activity); EndActivity = (Button)FindViewById(Resource.Id.records_controller_end_activity); AddActivity = (Button)FindViewById(Resource.Id.records_controller_add_activity); GetActivity = (Button)FindViewById(Resource.Id.records_controller_get_activity); DeleteActivity = (Button)FindViewById(Resource.Id.records_controller_delete_activity); BeginActivity.Click += delegate { BeginActivityRecord(); }; EndActivity.Click += delegate { EndActivityRecord(); }; AddActivity.Click += delegate { AddActivityRecord(); }; GetActivity.Click += delegate { GetActivityRecord(); }; DeleteActivity.Click += delegate { DeleteActivityRecord(); }; }
//Sign-in and authorization method. //The authorization screen will display up if authorization has not granted by the current account. private async void SignIn() { Log.Info(TAG, "Begin sign in"); IList <Scope> scopeList = new List <Scope>(); // Add scopes to apply for. The following only shows an example. // Developers need to add scopes according to their specific needs. // View and save steps in HUAWEI Health Kit. scopeList.Add(new Scope(Scopes.HealthkitStepRead)); scopeList.Add(new Scope(Scopes.HealthkitStepWrite)); // View and save height and weight in HUAWEI Health Kit. scopeList.Add(new Scope(Scopes.HealthkitHeightweightRead)); scopeList.Add(new Scope(Scopes.HealthkitHeightweightWrite)); // View and save the heart rate data in HUAWEI Health Kit. scopeList.Add(new Scope(Scopes.HealthkitHeartrateRead)); scopeList.Add(new Scope(Scopes.HealthkitHeartrateWrite)); // View and save activityRecord in HUAWEI Health Kit. scopeList.Add(new Scope(Scopes.HealthkitActivityRead)); scopeList.Add(new Scope(Scopes.HealthkitActivityWrite)); // View and save sleep data in HUAWEI Health Kit. scopeList.Add(new Scope(Scopes.HealthkitSleepRead)); scopeList.Add(new Scope(Scopes.HealthkitSleepWrite)); // Configure authorization parameters. HuaweiIdAuthParamsHelper AuthParamsHelper = new HuaweiIdAuthParamsHelper(HuaweiIdAuthParams.DefaultAuthRequestParam); HuaweiIdAuthParams AuthParams = AuthParamsHelper.SetIdToken().SetAccessToken().SetScopeList(scopeList).CreateParams(); // Initialize the HuaweiIdAuthService object. AuthService = HuaweiIdAuthManager.GetService(this, AuthParams); // Silent sign-in. If authorization has been granted by the current account, // the authorization screen will not display. This is an asynchronous method. var AuthHuaweiIdTask = AuthService.SilentSignInAsync(); try { await AuthHuaweiIdTask; if (AuthHuaweiIdTask.IsCompleted && AuthHuaweiIdTask.Result != null) { if (AuthHuaweiIdTask.Exception == null) { Log.Info(TAG, "SilentSignIn success"); Toast.MakeText(this, "SilentSignIn success", ToastLength.Long).Show(); // anfter Huawei ID authorization, perform Huawei Health authorization. CheckOrAuthorizeHealth(); } else { // The silent sign-in fails. // This indicates that the authorization has not been granted by the current account. Log.Info(TAG, "Sign failed status:" + AuthHuaweiIdTask.Exception.Message); Log.Info(TAG, "Begin sign in by intent"); // Call the sign-in API using the getSignInIntent() method. Intent signInIntent = AuthService.SignInIntent; // Display the authorization screen by using the startActivityForResult() method of the activity. StartActivityForResult(signInIntent, Constants.RequestSignInLogin); } } } catch (Exception ex) { Log.Info(TAG, "Sign failed :" + ex.Message); Log.Info(TAG, "Begin sign in by intent"); // Call the sign-in API using the getSignInIntent() method. Intent signInIntent = AuthService.SignInIntent; // Display the authorization screen by using the startActivityForResult() method of the activity. StartActivityForResult(signInIntent, Constants.RequestSignInLogin); } }