• <small id='pOHok'></small><noframes id='pOHok'>

  • <tfoot id='pOHok'></tfoot>

        <bdo id='pOHok'></bdo><ul id='pOHok'></ul>
    1. <i id='pOHok'><tr id='pOHok'><dt id='pOHok'><q id='pOHok'><span id='pOHok'><b id='pOHok'><form id='pOHok'><ins id='pOHok'></ins><ul id='pOHok'></ul><sub id='pOHok'></sub></form><legend id='pOHok'></legend><bdo id='pOHok'><pre id='pOHok'><center id='pOHok'></center></pre></bdo></b><th id='pOHok'></th></span></q></dt></tr></i><div id='pOHok'><tfoot id='pOHok'></tfoot><dl id='pOHok'><fieldset id='pOHok'></fieldset></dl></div>

    2. <legend id='pOHok'><style id='pOHok'><dir id='pOHok'><q id='pOHok'></q></dir></style></legend>

        使用 LibGDX 进行 Google 登录

        时间:2023-05-18

            <tbody id='TD6Lt'></tbody>
            <bdo id='TD6Lt'></bdo><ul id='TD6Lt'></ul>
            • <i id='TD6Lt'><tr id='TD6Lt'><dt id='TD6Lt'><q id='TD6Lt'><span id='TD6Lt'><b id='TD6Lt'><form id='TD6Lt'><ins id='TD6Lt'></ins><ul id='TD6Lt'></ul><sub id='TD6Lt'></sub></form><legend id='TD6Lt'></legend><bdo id='TD6Lt'><pre id='TD6Lt'><center id='TD6Lt'></center></pre></bdo></b><th id='TD6Lt'></th></span></q></dt></tr></i><div id='TD6Lt'><tfoot id='TD6Lt'></tfoot><dl id='TD6Lt'><fieldset id='TD6Lt'></fieldset></dl></div>

              <legend id='TD6Lt'><style id='TD6Lt'><dir id='TD6Lt'><q id='TD6Lt'></q></dir></style></legend>

              <small id='TD6Lt'></small><noframes id='TD6Lt'>

                1. <tfoot id='TD6Lt'></tfoot>
                  本文介绍了使用 LibGDX 进行 Google 登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我有问题.我正在用 LibGDX 制作游戏.现在我想实现谷歌登录.我到处搜索,但找不到任何东西.

                  I've a problem. I'm making a game with LibGDX. Now I want to implement Google Sign-In. I searched everywhere, but can't find anything.

                  我需要一个解析器来抽象特定平台的代码,但我不知道该怎么做.有人可以帮忙吗?

                  What I need is a Resolver to abstract code for specific platform, but I don't know how to do it. Can someone help?

                  编辑

                  这是代码,这是我的 Android 解析器:

                  Here's the code, this is my Android Resolver:

                  public GoogleResolverAndroid(final Context context) {
                  
                      handler = new Handler();
                      this.context = context;
                  
                      GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                              .requestEmail()
                              .build();
                  
                      mGoogleApiClient = new GoogleApiClient.Builder(this.context)
                              .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
                              .addConnectionCallbacks(this)
                              .addOnConnectionFailedListener(this)
                              .build();
                  }
                  @Override
                  public void loginGoogle() {
                      signIn();
                  }
                  
                  @Override
                  public boolean getIsLoggedInGoogle() {
                      return isLoggedIn;
                  }
                  
                  public void signIn() {
                  
                      Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
                      ((AndroidLauncher)context).startActivityForResult(signInIntent, RC_SIGN_IN);
                      mGoogleApiClient.connect();
                  
                  }
                  
                  private void signOut() {
                      Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback(
                              new ResultCallback<Status>() {
                                  @Override
                                  public void onResult(Status status) {
                                      isLoggedIn = false;
                                  }
                              });
                  }
                  
                  @Override
                  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
                  
                      // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
                      if (requestCode == RC_SIGN_IN) {
                          GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
                          handleSignInResult(result);
                      }
                  
                      if (requestCode == REQUEST_RESOLVE_ERROR) {
                          mResolvingError = false;
                          if (resultCode == RESULT_OK) {
                              // Make sure the app is not already connected or attempting to connect
                              if (!mGoogleApiClient.isConnecting() &&
                                      !mGoogleApiClient.isConnected()) {
                                  mGoogleApiClient.connect();
                              }
                          }
                      }
                      } 
                  //some code other code
                  //
                  //
                  //
                  
                  
                  
                  
                  @Override
                  public void onConnected(@Nullable Bundle bundle) {
                  
                      OptionalPendingResult<GoogleSignInResult> opr = Auth.GoogleSignInApi.silentSignIn(mGoogleApiClient);
                      if (opr.isDone())
                      {
                          Gdx.app.debug(TAG, "Loggato");
                          GoogleSignInResult result = opr.get();
                          handleSignInResult(result);
                      } else {
                          opr.setResultCallback(new ResultCallback<GoogleSignInResult>() {
                              @Override
                              public void onResult(GoogleSignInResult googleSignInResult) {
                                  handleSignInResult(googleSignInResult);
                              }
                          });
                      }
                  }
                  
                  @Override
                  public void onConnectionSuspended(int i) {
                      Gdx.app.debug(TAG, "onConnectionSuspended ma non so perchè");
                  }
                  

                  这是我在 libgdx 中调用解析器方法的类

                  and this is my class that call the resolver method in libgdx

                         // Google
                      googleLoginButton = new LoginButton(tbs, stage, main);
                      googleLoginButton.setPosition(stage.getViewport().getWorldWidth()/2-googleLoginButton.getWidth() - 10,
                              stage.getViewport().getWorldHeight()/2-googleLoginButton.getHeight()/2 - 200);
                  
                      googleLoginButton.addListener(new ClickListener() {
                          @Override
                          public void clicked(InputEvent event, float x, float y) {
                              main.googleResolver.loginGoogle();
                              googlePrefs = main.googleResolver.getGooglePrefs();
                  
                              gLoginIn = true;
                  
                              Gdx.app.debug(TAG, googlePrefs.toString());
                          }
                      });
                  

                  推荐答案

                  我为我的游戏解决这个问题的方法是使用 接口.因此,您必须编写 Android 和 iOS 特定代码,在核心游戏中使用此接口.

                  The way I solved this for my game was with the use of Interfacing. So you have to write Android and iOS specific code that use this interfaces from your core game.

                  这篇关于使用 LibGDX 进行 Google 登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:解析 ISO 8601 字符串本地日期时间,就像在 UTC 中 下一篇:如何将 Sprite 纹理更改为动画

                  相关文章

                  最新文章

                  <tfoot id='DwznY'></tfoot>

                  • <bdo id='DwznY'></bdo><ul id='DwznY'></ul>
                  1. <legend id='DwznY'><style id='DwznY'><dir id='DwznY'><q id='DwznY'></q></dir></style></legend>
                    1. <small id='DwznY'></small><noframes id='DwznY'>

                      <i id='DwznY'><tr id='DwznY'><dt id='DwznY'><q id='DwznY'><span id='DwznY'><b id='DwznY'><form id='DwznY'><ins id='DwznY'></ins><ul id='DwznY'></ul><sub id='DwznY'></sub></form><legend id='DwznY'></legend><bdo id='DwznY'><pre id='DwznY'><center id='DwznY'></center></pre></bdo></b><th id='DwznY'></th></span></q></dt></tr></i><div id='DwznY'><tfoot id='DwznY'></tfoot><dl id='DwznY'><fieldset id='DwznY'></fieldset></dl></div>