beginUserInitiatedSignIn

beginUserInitiatedSignIn

本文介绍了如何连接到Google Play服务和负载排行榜的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我的游戏与谷歌播放服务进行连接。我已经在Android开发者阅读文档并尝试以下类型的非数字样本,仍然无法加载排行榜。

我有进口baseGameUtils,但我用andengine,所以我没有使用从谷歌扩展BaseGameActivity。

我有什么至今:结果
- GooglePlayServicesUtil.isGooglePlayServicesAvailable(本)返回成功结果
- startActivityForResult(pickAccountIntent,REQUEST_ code_PICK_ACCOUNT);是运作良好,从我得到的onActivityResult我的账户名(.​​.);结果
- 我已经把这个在我的清单。

 <元数据机器人:名字=com.google.android.gms.games.APP_ID
        机器人:值=@字符串/ APP_ID/>

我的问题是结果
1.我可以使用谷歌播放服务,而不扩展BaseGameActivity?结果
2.如果我使用gameHelper.beginUserInitiatedSignIn();之后,我得到了我的帐户名,我得到这个日志上的猫。 (这是什么意思连接?因为我仍然有上下一题错误)

  08-25 00:09:01.890:D / BaseGameActivity(11222):isGooglePlayServicesAvailable返回0
08-25 00:09:01.890:D / BaseGameActivity(11222):beginUserInitiatedSignIn:启动新的登录流程。
08-25 00:09:01.890:D / BaseGameActivity(11222):所有客户端已连接。登入成功。
08-25 00:09:01.890:D / BaseGameActivity(11222):所有请求连接的客户端。登入成功了!

3。我如何使用connect()?我已阅读并试了一下gameClient和GameClientBuilder,但我不知道如何使用它。当我试图运行此code。

  startActivityForResult(gameHelper.getGamesClient()getAllLeaderboardsIntent(),RC_UNUSED。);

我得到这个日志。

  08-25 00:09:05.660:E / AndroidRuntime(11222):java.lang.IllegalStateException:未连接。调用connect()并等待onConnected()被调用。

4。使用排行榜,我知道我必须使用code从谷歌Play商店如CgkIx * ** * AIQAA。但我没有找到我的地方,必须把这个code加载排行榜。

对不起长的问题,但我认为如果只为连接,要么获得成就或页首横幅会回答我的问题,所有的样本。请不要告诉我看到类型的非数字样本,我这样做,我需要另一个样品code。

更新,我的文档片断code

 公共类MainMenu的扩展活动
实现OnClickListener,GooglePlayServicesClient.ConnectionCallbacks,GooglePlayServicesClient.OnConnectionFailedListener,GameHelperListener {@覆盖
公共无效的onCreate(捆绑savedInstanceState){
  super.onCreate(savedInstanceState);
  的setContentView(R.layout.main_menu);
  gameHelper =新GameHelper(本);
}@覆盖
公共无效的onClick(视图v){
  如果(v.equals(loadData)){
    如果(gameHelper.isSignedIn()){
      gameHelper.setup(这一点,GameHelper.CLIENT_GAMES,Scopes.GAMES);
      startActivityForResult(gameHelper.getGamesClient()getAllLeaderboardsIntent(),RC_UNUSED);
    }
  }
  否则如果(v.equals(loginButton)){
    意向googlePicker = AccountPicker.newChooseAccountIntent(NULL,NULL,新的String [] {} GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE,真实,NULL,NULL,NULL,NULL);
    startActivityForResult(googlePicker,REQUEST_ code_PICK_ACCOUNT);
  }
}@覆盖
保护无效的onActivityResult(最终诠释请求code,最终诠释结果code,最终意向数据){
  如果(要求code == REQUEST_ code_RECOVER_PLAY_SERVICES){
    如果(结果code == RESULT_CANCELED){
      Toast.makeText(这一点,谷歌播放服务必须安装,Toast.LENGTH_SHORT).show();
      完();
    }
    返回;
  }
  否则,如果(要求code == REQUEST_ code_PICK_ACCOUNT){
    如果(结果code == RESULT_OK){
      字符串帐户名= data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
      gameHelper.beginUserInitiatedSignIn();
    }
    否则,如果(结果code == RESULT_CANCELED){
      Toast.makeText(这一点,此应用程序需要一个谷歌帐户,Toast.LENGTH_SHORT).show();
      完();
    }
    返回;
  }
  super.onActivityResult(要求code,结果code,数据);
}//这2种方法不叫,这是也是因为我的code是错的?
@覆盖
公共无效onSignInFailed(){
  Log.d(失败的标志,抢);
}@覆盖
公共无效onSignInSucceeded(){
  Log.d(抢,关于登录成功);
}}


解决方案

  1. 是的。看看在 BaseGameActivity 来源,并看到它在很大程度上只是包装 GameHelper 。您可以实现对呼叫 GameHelper 自己 - 其实,你也许可以复制一些code直接从 BaseGameActivity 。我有点困惑,因为它似乎你的code已经使用 GameHelper 。它看起来像你是混合 GameHelper 将调用 BaseGameActivity 来电。你不能做到这一点,它会导致......就像你的错误越来越


  2. 您看到的LogCat中表示所有的客户端连接。默认调用 GameHelper.setup()只是要求游戏客户端。如果你不使用 BaseGameActivity ,并希望不同的客户端,这样做:

      gameHelper =新GameHelper(本);
    gameHelper.setup(这一点,GameHelper.CLIENT_GAMES | GameHelper.CLIENT_PLUS);


  3. beginUserInitiatedSignIn()是当它完成一个回调的异步方法。你运行它呀? GameHelper.GameHelperListener 是要实现的接口。如果您正在使用gameHelper,确保注册回调。请参阅这个在上面的建立呼叫?这是注册回调(这个是我的主要活动)。

    正如我前面所说,它看起来像你是混合 GameHelper BaseGameActivity 电话呼叫。在 GameHelper 已连接的是 BaseGameActivity.mHelper 实例,而不是任何 GameHelper 你可能已经实例化。确保如果你正在使用 BaseGameActivity 您没有使用 GameHelper 以及这一点。


  4. 如果你想显示一个单一的排行榜,使用 GamesClient.getLeaderboardIntent(字符串,INT)或方法来获取意图。该字符串是code你有(CgkIx **** AIQAA)。

      startActivityForResult(gameHelper.getGamesClient()。getLeaderboardIntent(
            leaderboard_id,RC_UNUSED);

    再次确保你使用了正确的 getGamesClient()方法,取决于如果您使用的是 BaseGameActivity GameHelper 直接


I want to connect my game with google play service. i have read documentation on android developer and try to following type-a-number sample and still can't load leaderboard.

i have import baseGameUtils, but i use andengine so i didn't use extends BaseGameActivity from google.

what i have until now:
- GooglePlayServicesUtil.isGooglePlayServicesAvailable(this) return success
- startActivityForResult(pickAccountIntent, REQUEST_CODE_PICK_ACCOUNT); is working well and i got my account name from onActivityResult(..);
- i already put this on my manifest.

<meta-data android:name="com.google.android.gms.games.APP_ID"
        android:value="@string/app_id" />

my questions are
1. can i use google play service without extends BaseGameActivity?
2. if i use gameHelper.beginUserInitiatedSignIn(); after i got my account name, i got this on log cat. (what this connected mean? because i still got error on next question)

08-25 00:09:01.890: D/BaseGameActivity(11222): isGooglePlayServicesAvailable returned 0
08-25 00:09:01.890: D/BaseGameActivity(11222): beginUserInitiatedSignIn: starting new sign-in flow.
08-25 00:09:01.890: D/BaseGameActivity(11222): All clients now connected. Sign-in successful.
08-25 00:09:01.890: D/BaseGameActivity(11222): All requested clients connected. Sign-in succeeded!

3 . how do i use connect()? i have read and tried about gameClient and GameClientBuilder but i have no idea how to use that. when i tried run this code.

startActivityForResult(gameHelper.getGamesClient().getAllLeaderboardsIntent(), RC_UNUSED);

i got this log.

08-25 00:09:05.660: E/AndroidRuntime(11222): java.lang.IllegalStateException: Not connected. Call connect() and wait for onConnected() to be called.

4 . to use leaderboard i know i must use code from google play store such as CgkIx****AIQAA. but i didn't found where i must put this code to load leaderboard.

sorry for long question, but i think if there is a sample that only for connect and either access achievement or leaderboard it will answer all my question. please don't tell me to see type-a-number sample, i did that and i need another sample code.

update, my snipped code

public class MainMenu extends Activity
implements OnClickListener, GooglePlayServicesClient.ConnectionCallbacks, GooglePlayServicesClient.OnConnectionFailedListener, GameHelperListener{

@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main_menu);
  gameHelper = new GameHelper(this);
}

@Override
public void onClick(View v) {
  if(v.equals(loadData)) {
    if(gameHelper.isSignedIn()) {
      gameHelper.setup(this, GameHelper.CLIENT_GAMES, Scopes.GAMES);
      startActivityForResult(gameHelper.getGamesClient().getAllLeaderboardsIntent(), RC_UNUSED);
    }
  }
  else if(v.equals(loginButton)) {
    Intent googlePicker = AccountPicker.newChooseAccountIntent(null,null,new String[]{GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE},true,null,null,null,null) ;
    startActivityForResult(googlePicker, REQUEST_CODE_PICK_ACCOUNT);
  }
}

@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
  if(requestCode==REQUEST_CODE_RECOVER_PLAY_SERVICES) {
    if (resultCode == RESULT_CANCELED) {
      Toast.makeText(this, "Google Play Services must be installed.", Toast.LENGTH_SHORT).show();
      finish();
    }
    return;
  }
  else if(requestCode==REQUEST_CODE_PICK_ACCOUNT) {
    if (resultCode == RESULT_OK) {
      String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
      gameHelper.beginUserInitiatedSignIn();
    }
    else if (resultCode == RESULT_CANCELED) {
      Toast.makeText(this, "This application requires a Google account.", Toast.LENGTH_SHORT).show();
      finish();
    }
    return;
  }
  super.onActivityResult(requestCode, resultCode, data);
}

// this 2 methods not called, is this also because my code is wrong?
@Override
public void onSignInFailed() {
  Log.d("rush", "on sign in failed");
}

@Override
public void onSignInSucceeded() {
  Log.d("rush", "on sign in succeed");
}

}
解决方案
  1. Yes. Take a look at the BaseGameActivity source and see that it largely just wraps GameHelper. You can implement the calls to GameHelper yourself - in fact, you can probably copy some code directly from BaseGameActivity. I'm a bit confused, because it appears that your code is already using GameHelper. It looks like you are mixing GameHelper calls with BaseGameActivity calls. You cannot do this, and it will result in... errors like you are getting.

  2. The LogCat you see means that all of your clients are connected. The default call to GameHelper.setup() just requests the Games client. If you aren't using BaseGameActivity and want different clients, do:

    gameHelper = new GameHelper(this);
    gameHelper.setup(this, GameHelper.CLIENT_GAMES | GameHelper.CLIENT_PLUS);
    

  3. beginUserInitiatedSignIn() is an asynchronous method with a callback when it finishes. Are you running it that way? GameHelper.GameHelperListener is the interface to implement. If you are using gameHelper, make sure to register the callback. See the this in the setup call above? That's registering the callback (this is my main activity).

    As I said above, it looks like you are mixing GameHelper calls with BaseGameActivity calls. The GameHelper that is connected is the BaseGameActivity.mHelper instance, not any GameHelper you might have instantiated. Make sure that if you are using BaseGameActivity that you are not using GameHelper as well.

  4. If you want to display a single leaderboard, use the GamesClient.getLeaderboardIntent(string, int) or method to get the Intent. The string is the code you have (CgkIx****AIQAA).

    startActivityForResult(gameHelper.getGamesClient().getLeaderboardIntent(
            leaderboard_id, RC_UNUSED);
    

    Again, make sure you are using the correct getGamesClient() method, depending on if you are using BaseGameActivity or GameHelper directly.

这篇关于如何连接到Google Play服务和负载排行榜的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 12:18