2

我正在尝试将 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 登录产生负面影响,但仍然没有运气。

4

2 回答 2

7

我遇到了同样的问题,然后我在日志中注意到了这一点:“活动正在作为新任务启动,因此取消活动结果”

在我的 libgdx 游戏的 AndroidManifest.xml 文件中,我设置了这个属性:'android:launchMode="singleInstance"' 删除它后,我就可以像示例应用程序一样使用 GPGS。

于 2013-08-15T02:02:49.623 回答
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: android.os.BinderProxy@40ee3de0}}
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!

更新:

怎么样 - 这只是一个复制和粘贴错误,还是您的程序缺少 Public 上的“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 ..........@gmail.com

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 控制台进行任何更改.

于 2013-07-10T09:59:47.870 回答