2013-07-10 57 views
2

我試圖在我的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登錄造成負面影響,但仍然沒有運氣。

回答

7

我有同樣的問題,然後我在日誌中注意到了這一點:「活動推出的一項新的任務,所以取消活動結果」

在我libgdx遊戲的AndroidManifest.xml文件,我已經建立這個屬性:'android:launchMode =「singleInstance」'一旦我刪除了,我就可以像使用示例應用程序一樣使用GPGS。

1

我還沒有詳細看過你的代碼。基本上我使用提供的GameHelper(我認爲你已經完成了相同的工作),並且將我需要從BaseGameUtils獲得的所有內容放入我的片段中。我建議你看一下TypeANumber的成功追蹤,看看你錯過了什麼。這裏是我的痕跡之一:

07-04 10:21:54.511: D/ian_(1781): MultiTab3 beginUserInitiatedSignIn 
04 10:21:54.531: D/ian_(1781): isGooglePlayServicesAvailable returned 0 
07-04 10:21:54.531: D/ian_(1781): beginUserInitiatedSignIn: continuing pending sign-in flow. 
07-04 10:21:54.611: D/ian_(1781): resolveConnectionResult: trying to resolve result: C  onnectionResult{statusCode=SIGN_IN_REQUIRED, resolution=PendingIntent{40f3ed38: [email protected]}} 
07-04 10:21:54.611: D/ian_(1781): result has resolution. Starting it. 
07-04 10:21:54.621: D/ian_(1781): startResolutionForResult - this may be prob ? 
07-04 10:23:29.480: D/ian_(1781): MultiPlayer onActivityResult called9001-1null 
07-04 10:23:29.520: D/ian_(1781): MultiPlayer passing onActivityResult to MultiTab3 Req/Resp/Data=9001-1null 
07-04 10:23:29.520: D/ian_(1781): MultiTab3 onActivityResult - passing through to GameHelper ...9001-1null 
07-04 10:23:29.520: D/ian_(1781): onActivityResult, req 9001 response -1 
07-04 10:23:29.520: D/ian_(1781): responseCode == RESULT_OK. So connecting. 
07-04 10:23:30.130: D/ian_(1781): onConnected: connected! client=1 
07-04 10:23:30.130: D/ian_(1781): All clients now connected. Sign-in successful. 
07-04 10:23:30.130: D/ian_(1781): All requested clients connected. Sign-in succeeded! 

更新:

這個什麼 - 這只是一個複製和粘貼錯誤或程序上的公共缺少「P」? (您需要進行此調用)

@Override 
    ublic void onStart() 
    { 
     super.onStart(); 
     aHelper.onStart(this); 
    } 

更新2:

根據您所做的工作,你現在已經消除了編程錯誤的可能性。我還沒有看到導致此問題的設置錯誤。不過我確實遇到過這種(類似):

onConnectionFailed: result 4 
onConnectionFailed: since user initiated sign-in, trying to resolve problem 
statusCode=SIGN_IN_REQUIRED resolution=PendingIntent 
result has resolution. Starting it. 

Explanation from google docs "The client attempted to connect to the service but the user is not signed in" 

n.b. Google setting is showing that we are signed in as [email protected] 

further investigation **suggests** that this may be because of a set up problem in the 
google play api console and/or google play developer console ... 

我還注意到你提到過Google API控制檯。我建議您在開發者控制檯中創建一個新集合定義,並且不要通過API控制檯進行任何修改。我並不是說你已經改變了API控制檯中的東西 - 我只是覺得創建一套新的定義和(我正在重複自己,我知道)在這一點上更容易不要通過API進行任何更改控制檯

+0

我還沒有對GameHelper進行任何更改。我只是做了一個調試,並且正在調用'startResolutionForResult' - 這就是'SignInActivity必須以startActivityForResult'開始的錯誤返回的地方。 – eby

+0

據我所知,你目前沒有登錄,所以startResolutionForResult被調用,你應該看到谷歌「選擇一個帳戶」對話框。它彈出嗎? – IanB

+0

不,它沒有。當我開始登錄時,它看起來像是彈出一個非常簡短的內容,但隨後會顯示一個「未知錯誤」對話框,並顯示確定按鈕。 – eby

相關問題