[英]Error to integrate HMS in Android Studio , SignInCenter not defined
At the time of implementing the HMS the "SignInCenter" function is not recognized, I have already added all the imports indicated in the documentation but it still does not work.在实施 HMS 时,无法识别“SignInCenter”function,我已经添加了文档中指示的所有导入,但它仍然不起作用。
there has no this function named "SignInCenter" in the API documentation, if you want to use Account kit, here is github codelab link: https://github.com/HMS-Core/huawei-account-demo there has no this function named "SignInCenter" in the API documentation, if you want to use Account kit, here is github codelab link: https://github.com/HMS-Core/huawei-account-demo
1.call the signIn with the Android standard interface startActivityForResult(); 1.用Android标准接口startActivityForResult()调用signIn;
private void signIn() {
mAuthParam = new HuaweiIdAuthParamsHelper(HuaweiIdAuthParams.DEFAULT_AUTH_REQUEST_PARAM)
.setIdToken()
.setAccessToken()
.createParams();
mAuthManager = HuaweiIdAuthManager.getService(HuaweiIdActivity.this, mAuthParam);
startActivityForResult(mAuthManager.getSignInIntent(), Constant.REQUEST_SIGN_IN_LOGIN);
}
2.get the result whit onActivityResult(). 2.通过onActivityResult()获取结果。
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == Constant.REQUEST_SIGN_IN_LOGIN) {
//login success
//get user message by parseAuthResultFromIntent
Task<AuthHuaweiId> authHuaweiIdTask = HuaweiIdAuthManager.parseAuthResultFromIntent(data);
if (authHuaweiIdTask.isSuccessful()) {
AuthHuaweiId huaweiAccount = authHuaweiIdTask.getResult();
Log.i(TAG, huaweiAccount.getDisplayName() + " signIn success ");
Log.i(TAG,"AccessToken: " + huaweiAccount.getAccessToken());
validateIdToken(huaweiAccount.getIdToken());
} else {
Log.i(TAG, "signIn failed: " + ((ApiException) authHuaweiIdTask.getException()).getStatusCode());
}
}
if (requestCode == Constant.REQUEST_SIGN_IN_LOGIN_CODE) {
//login success
Task<AuthHuaweiId> authHuaweiIdTask = HuaweiIdAuthManager.parseAuthResultFromIntent(data);
if (authHuaweiIdTask.isSuccessful()) {
AuthHuaweiId huaweiAccount = authHuaweiIdTask.getResult();
Log.i(TAG, "signIn get code success.");
Log.i(TAG,"ServerAuthCode: " + huaweiAccount.getAuthorizationCode());
/**** 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.i(TAG, "signIn get code failed: " + ((ApiException) authHuaweiIdTask.getException()).getStatusCode());
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.