我試圖在我的libGDX遊戲中實現Google Play遊戲服務。我在這裏跟着教程:http://helios.hud.ac.uk/u1070589/blog/?p=202Google Play遊戲服務&libGDX「SignInActivity必須以startActivityForResult開始」
當我的遊戲加載時,我創建一個新的GameHelper對象並調用它的設置方法。我已經調試過這個部分,並且沒有任何問題就完成了。我在主菜單上放置了一個GPGS按鈕,當它被點擊時,我在我的主要Android活動中調用Login()
方法。
此時mConnectionResult.startResolutionForResult(mActivity, RC_RESOLVE)
呼叫在resolveConnectionResult
方法(GameHelper類)將返回錯誤:
E/SignInActivity(21930): SignInActivity must be started with 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,可以在活動中看到。我嘗試刪除Swarm,看看是否會對GPGS登錄造成負面影響,但仍然沒有運氣。
我還沒有對GameHelper進行任何更改。我只是做了一個調試,並且正在調用'startResolutionForResult' - 這就是'SignInActivity必須以startActivityForResult'開始的錯誤返回的地方。 – eby
據我所知,你目前沒有登錄,所以startResolutionForResult被調用,你應該看到谷歌「選擇一個帳戶」對話框。它彈出嗎? – IanB
不,它沒有。當我開始登錄時,它看起來像是彈出一個非常簡短的內容,但隨後會顯示一個「未知錯誤」對話框,並顯示確定按鈕。 – eby