我正在尝试将 Google Play 游戏服务实施到我的 libGDX 游戏中。我在这里按照教程:http ://helios.hud.ac.uk/u1070589/blog/?p=202
当我的游戏加载时,我创建一个新的 GameHelper 对象并调用它的 setup 方法。我已经调试了这部分,它完成没有任何问题。我在主菜单上放置了一个 GPGS 按钮,单击它时我会Login()
在我的主 Android Activity 中调用该方法。
此时方法(GameHelper类)mConnectionResult.startResolutionForResult(mActivity, RC_RESOLVE)
中的调用返回错误:resolveConnectionResult
E/SignInActivity(21930):SignInActivity 必须以 startActivityForResult 启动
ConnectionResult 对象 (mConnectionResult) 没有可用的名为 startActivityForResult 的公共方法,因此我不能只更改 startResolutionForResult 调用。
在beginUserInitiatedSignIn()
方法 (GameHelper) 中,连接返回ConnectionResult.SUCCESS
. 当resolveConnectionResult()
被调用时,mConnectionResult.hasResolution()
也返回 true。
我已经仔细检查了我的调试密钥是否与 Google API 控制台中我的应用程序的条目匹配。我检查了我的应用 ID 是否与 Google Play 开发者控制台上显示的 ID 相符。
我已经设法让 Type-a-Number 示例应用程序正常工作。这是我的主要 Android 活动:
package com.eb.droid;
import android.content.Intent;
import android.view.Window;
import android.view.WindowManager;
import com.badlogic.gdx.backends.android.AndroidApplication;
import com.badlogic.gdx.backends.android.AndroidApplicationConfiguration;
import com.swarmconnect.Swarm;
import com.eb.GoogleInterface;
import com.google.example.games.basegameutils.GameHelper;
import com.google.example.games.basegameutils.GameHelper.GameHelperListener;
public final class AndroidGame extends AndroidApplication implements GameHelperListener, GoogleInterface
{
private final int RC_RESOLVE = 5000, RC_UNUSED = 5001; //request codes we use when invoking an external activity
private final SwarmData swarmData = new SwarmData();
private GameHelper aHelper;
public AndroidGame()
{
aHelper = new GameHelper(this);
aHelper.enableDebugLog(true, "MYTAG");
}
public final void onCreate(android.os.Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
AndroidApplicationConfiguration cfg = new AndroidApplicationConfiguration();
// Disable hardware functions to save battery power.
cfg.useAccelerometer = false;
cfg.useCompass = false;
cfg.useGL20 = true;
aHelper.setup(this);
setSwarmKeyPartA();
initialize(new Game(this, swarmData), cfg);
// Activate Swarm if user is already logged-in. App won't nag player to log-in, they always have to
// do it manually via the Swarn dashboard via the title screen.
//Log.d(LOG, "onCreate() Swarm.isLoggedIn() = " + Swarm.isLoggedIn());
if (Swarm.isLoggedIn())
{
Swarm.setActive(this);
}
}
public void onResume()
{
super.onResume();
if (Swarm.isLoggedIn())
{
Swarm.setActive(this);
Swarm.init(this, swarmData.swarmAppID, swarmData.swarmAppKey);
}
}
public void onPause()
{
super.onPause();
Swarm.setInactive(this);
}
@Override
ublic void onStart()
{
super.onStart();
aHelper.onStart(this);
}
@Override
public void onStop()
{
super.onStop();
aHelper.onStop();
}
@Override
public void onActivityResult(int request, int response, Intent data)
{
super.onActivityResult(request, response, data);
aHelper.onActivityResult(request, response, data);
}
public void onSignInFailed()
{
System.out.println("sign in failed");
}
public void onSignInSucceeded()
{
System.out.println("sign in succeeded");
}
public void Login()
{
try
{
runOnUiThread(new Runnable()
{
@Override
public void run()
{
aHelper.beginUserInitiatedSignIn();
}
});
}
catch (final Exception ex)
{
}
}
public void LogOut()
{
try
{
runOnUiThread(new Runnable()
{
@Override
public void run()
{
aHelper.signOut();
}
});
}
catch (final Exception ex)
{
}
}
public boolean getSignedIn()
{
return aHelper.isSignedIn();
}
public void submitScore(int _score)
{
System.out.println("in submit score");
aHelper.getGamesClient().submitScore(getString(R.string.leaderboard_high_scores), _score);
}
public void showAchievements()
{
startActivityForResult(aHelper.getGamesClient().getAchievementsIntent(), RC_UNUSED);
}
public void showLeaderboards()
{
startActivityForResult(aHelper.getGamesClient().getAllLeaderboardsIntent(), RC_UNUSED);
}
public void getScoresData()
{
}
}
我的应用程序目前还实现了 Swarm,如 Activity 中所示。我尝试删除 Swarm 以查看这是否会对 GPGS 登录产生负面影响,但仍然没有运气。