如何检查Android设备上是否提供Google Play游戏帐户?

时间:2016-02-09 21:27:38

标签: java android libgdx google-play-services google-play-games

我想知道Android设备上是否有可注册为Google Play游戏帐户的帐户。

我正在使用Java和LibGDX。

有什么想法吗?

1 个答案:

答案 0 :(得分:1)

修改 Google Play游戏不再需要提及here

的Google+帐户

问题:要求不必要的范围

// This way you won’t get a consent screen  
 GoogleApiClient gac = new GoogleApiClient.Builder(this, this, this)  
           .addApi(Games.API)  
           .build();  
 // This way you won’t get a consent screen  
  

在这种情况下,开发人员特别请求plus.login   范围。如果您要求plus.login,您的用户将获得同意   对话框。

解决方案:仅询问您需要的范围

public boolean isLoggedInGoogle() {
    AccountManager manager = (AccountManager) getSystemService(ACCOUNT_SERVICE);
    Account[] list = manager.getAccounts();

    for (Account account : list) {
        if (account.type.equalsIgnoreCase("com.google")) {
            return true;
        }
    }

    return false;
}
  

从GoogleApiClient构造中删除所有不需要的范围   以及您不再使用的任何API。

原始回答:

当用户使用提及herehere Google + 帐户登录时,可以使用 Google Play游戏帐户如果用户使用 Google 帐户登录,则可单独使用,因此我们的第一种方法是:

  1. 检查是否有Google帐户已登录
  2. 检查该用户是否已登录 Google +。
  3. 检查Android设备是否有 Google用户登录

    private GoogleApiClient buildGoogleApiClient() {
        return new GoogleApiClient.Builder(this)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(Plus.API, null)
                .addScope(Plus.SCOPE_PLUS_LOGIN)
                .build();
    }
    

    现在,检查Android设备是否有 Google+用户登录

    您可以尝试使用Google API客户端启动登录序列,如question中所述:

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content">
    
        <TextView
            android:id="@+id/textView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true"
            android:layout_marginLeft="29dp"
            android:layout_marginStart="29dp"
            android:layout_marginTop="69dp"
            android:text="Medium Text"
            android:textAppearance="?android:attr/textAppearanceMedium"/>
    
        <EditText
            android:id="@+id/editText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/textView"
            android:layout_toRightOf="@+id/textView"
            android:ems="10"
            android:inputType="numberSigned"
            android:textAppearance="?android:attr/textAppearanceMedium"/>
    </RelativeLayout>
    

    您也可以使用BaseGameUtilsPlay Games Services APIs。 在this link中有一些如何实现它的示例。