Google Paly登录无法在Android中使用 [英] Google Paly sign in Does not work in Android

查看:272
本文介绍了Google Paly登录无法在Android中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实现google play sing,但是它不起作用

我遵循开发人员文档来实施它,但是仍然无法正常工作

解决方案

第一步:在Google Play控制台中设置应用

  1. 创建一个新应用.
  2. 然后,在您的应用级build.gradle文件中,将Google Play服务声明为 依赖项:

    编译'com.google.android.gms:play-services-auth:16.0.1'

  3. 登录到Google Play控制台. .如果您尚未注册 在Google Play控制台之前,它会提示您进行注册.添加您的 应用到 Google Play控制台

  4. 将您的应用添加到Google Play控制台.

    a.打开游戏服务"页面,然后在页面上单击添加新游戏按钮 左边.

    b.由于您是从头开始创建的,因此请选择标签我不使用任何标签 我的游戏中已有Google API .输入您的应用名称,然后选择一个 类别,然后单击继续按钮.

    c.在详细信息"表单中,仅需要显示名称和描述 供测试用.必须先填写其他字段,然后才能发布 您的游戏.

    d.点击保存.

    e.打开右侧的喜欢的应用页面,然后点击 Android ,然后 在相关字段中输入应用程序的名称和程序包名称.

    f.启用适当的多人游戏设置,实时或开启 .

    g选择反隐私",然后单击保存并继续".

    h.现在,点击立即授权您的应用按钮.

    i.在包裹名称字段中,输入包裹名称,然后输入 签名证书指纹(SHA1)字段中的应用SHA1.和 点击确认.

    j.点击确认按钮后,您应该会看到新的客户端 此应用程序的ID.将其复制并粘贴到安全的地方.

    k.确保您要用来登录的帐户(位于的帐户 测试设备)列为开发人员项目中的测试人员 控制台设置(检查测试"部分中的列表)

第2步:在您的应用中进行以下更改

  1. 在清单文件中的application标记下,然后添加meta标记,然后 用客户端ID替换"您的APPID ".授权时得到的 您在Google Play控制台中的应用程序.
  2. 要在您的应用中添加标准的Google登录按钮,请添加一个 com.google.android .gms.common .SignIn Button 主要活动 布局.

  3. 在活动"的创建时"方法中的按钮"中启动演唱.

    signInButton = findViewById(R.id.sign_in_button)

  4. 当用户单击登录"按钮时.以下代码片段发送了 登录打算.

    signInButton.setOnClickListener(new View.OnClickListener(){

       @Override
       public void onClick(View view) {
          startSignInIntent();
          }
       });
    

  5. 以下代码片段显示了如何初始化startsignin()
    方法

    private void startSignInIntent(){

    GoogleSignInClient signInClient = GoogleSignIn.getClient(this,
    GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN);
    Intent intent = signInClient.getSignInIntent();
    startActivityForResult(intent, RC_SIGN_IN);
       }
    

  6. 在onActivityResult()回调中,处理返回的结果
    目的.

     **@Override
      protected void onActivityResult(int requestCode, int resultCode, Intent 
      data) {
     super.onActivityResult(requestCode, resultCode, data);
     if (requestCode == RC_SIGN_IN) {
          GoogleSignInResult result =  
          Auth.GoogleSignInApi.getSignInResultFromIntent(data);
        if (result.isSuccess()) {
           GoogleSignInAccount signedInAccount = result.getSignInAccount();
       } else {
           String message = result.getStatus().getStatusMessage();
           if (message == null || message.isEmpty()) {
               message = getString(R.string.signin_other_error);
           }
           new AlertDialog.Builder(this).setMessage(message)
                   .setNeutralButton("Login Fail", null).show();
       }
    

    } } **

I am implementing google play sing in, but it does not work

I follow the developer document to implement it but still, it does not work

解决方案

Step1 : Set up the app in the Google Play Console

  1. Create a new app .
  2. Then, in your app-level build.gradle file, declare Google Play services as a dependency:

    compile 'com.google.android.gms:play-services-auth:16.0.1'

  3. Sign in to Google Play Console. . If you haven't registered for the Google Play Console before, it will prompt you to register. Add your app to Google play console

  4. Add your app to Google play console .

    a. Open the Game Services page, then click the Add New Game button on the left.

    b. Since you are creating from scratch, select the tab I don't use any Google APIs in my game yet . Enter your app name and select a category, and then click the Continue button.

    c. In the Detail form Only the display name and description are required for testing. The other fields must be filled out before you can publish your game.

    d. Click save .

    e. Open the page Liked apps on the right and click Android and enter the name of the app and the package name in the relevant field.

    f. Enable the appropriate multiplayer settings, real-time or turn- based.

    g. Select anti privacy on and Click save and continue.

    h. Now click the Authorize your app now button .

    i. In the Package name field, enter your package name and enter you app SHA1 in the Signing certificate fingerprint (SHA1) field . and Click Confirm.

    j. After you click the Confirm button, you should see your new client ID for this application. Copy and paste it in a safe place .

    k. Make sure that the account you intend to sign in with (the account on the test device) is listed as a tester in the project on your Developer Console setup (check the list in the "Testing" section)

Step 2: Make the following changers in your app

  1. In your manifest file under application tag add then following meta tag and replace "YOUR APPID" with the client Id. That you got when you authorize your application in The Google play console.
  2. To add standard Google sign-in button in your app, Include a com.google.android .gms.common .SignIn Button the main activity layout.

  3. Initiate your sing in Button in On Create method of the Activity.

    signInButton = findViewById(R.id.sign_in_button)

  4. When the user click on the sign in button . The following code snip sends the sign in intend .

    signInButton.setOnClickListener(new View.OnClickListener() {

       @Override
       public void onClick(View view) {
          startSignInIntent();
          }
       });
    

  5. The following code snip shows you how to initialize the startsignin()
    Method

    private void startSignInIntent() {

    GoogleSignInClient signInClient = GoogleSignIn.getClient(this,
    GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN);
    Intent intent = signInClient.getSignInIntent();
    startActivityForResult(intent, RC_SIGN_IN);
       }
    

  6. In the onActivityResult() callback, handle the result from the returned
    Intent.

     **@Override
      protected void onActivityResult(int requestCode, int resultCode, Intent 
      data) {
     super.onActivityResult(requestCode, resultCode, data);
     if (requestCode == RC_SIGN_IN) {
          GoogleSignInResult result =  
          Auth.GoogleSignInApi.getSignInResultFromIntent(data);
        if (result.isSuccess()) {
           GoogleSignInAccount signedInAccount = result.getSignInAccount();
       } else {
           String message = result.getStatus().getStatusMessage();
           if (message == null || message.isEmpty()) {
               message = getString(R.string.signin_other_error);
           }
           new AlertDialog.Builder(this).setMessage(message)
                   .setNeutralButton("Login Fail", null).show();
       }
    

    } }**

这篇关于Google Paly登录无法在Android中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆