发生的事情很奇怪 每当启动用户登录时,都会显示“选择帐户”视图,选择帐户并单击“确定”后,将再次启动登录并返回相同的视图。单击取消将返回登录失败的游戏,为什么会发生这种情况?
在启动登录之前,LogCat中会出现以下内容:
03-06 13:53:06.797: D/PhoneWindow(2967): couldn't save which view has focus
because the focused view org.cocos2dx.lib.Cocos2dxGLSurfaceView@40537408 has no id.
我的实施方式如下:
public class myapp extends BaseGameActivity {
...
static Context mContext;
boolean mInSignInFlow = false;
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
mContext = myapp.this;
if(GooglePlayServicesUtil.isGooglePlayServicesAvailable (mContext) == ConnectionResult.SUCCESS){
GoogleApiClient.Builder builder =
new GoogleApiClient.Builder(this);
builder.addApi(Games.API)
.addScope(Games.SCOPE_GAMES);
mClient = builder.build();
}
}
@Override
protected void onStart() {
super.onStart();
if (!mInSignInFlow) {
// auto sign in
mClient.connect();
}
}
@Override
public void onSignInFailed() {
Log.w("Sign In", "Failed");
}
@Override
public void onSignInSucceeded() {
mInSignInFlow = true;
Log.w("Sign In", "Success");
}
public static void gameServicesSignIn() {
((myapp)mContext).runOnUiThread(new Runnable() {
public void run() {
((myapp)mContext).beginUserInitiatedSignIn();
}
});
}
我收到“登录失败”登录启动时以及从按钮点击调用gameServicesSignIn()时上面描述的情况..
答案 0 :(得分:1)
您似乎没有正确构建。通过流程查看(如果您扩展BaseGameActivity),Helper的基础设置已经为您完成。
来自BaseGameActivity
public GameHelper getGameHelper() {
if (mHelper == null) {
mHelper = new GameHelper(this, mRequestedClients);
mHelper.enableDebugLog(mDebugLog);
}
return mHelper;
}
@Override
protected void onCreate(Bundle b) {
super.onCreate(b);
if (mHelper == null) {
getGameHelper();
}
mHelper.setup(this);
}
然后还会设置监听器来调用你的onSignInFailed / Succeded。
我在您的代码中看到的设置内容适用于您未扩展BaseGameActivity的时间。
答案 1 :(得分:0)
cb.setImpressionsUseActivities(true);
设置完成后,您还需要将以下代码放在AndroidManifest.xml上:
<activity android:name="com.example.Activity"
android:excludeFromRecents="true"
android:theme="@android:style/Theme.Translucent.NoTitleBar"/>
我真的对cocos2d-x一无所知,所以我希望这会有所帮助。