/**
* 游客登录
* @param tokenLoginCallback 登录结果回调
*/
public void guestLogin(TokenLoginCallback tokenLoginCallback)
ngamesSdk.guestLogin(new NgamesSdk.TokenLoginCallback() {
@Override
public void onSuccess(TokenLoginResult.Data data) {
//登录成功
}
@Override
public void onError(BaseResult error) {
//登录失败
}
});
/**
* 登录GameSamba账号
* @param registerCallback
*/
public void loginGameSamba(final RegisterCallback registerCallback)
ngamesSdk.loginGameSamba(new NgamesSdk.RegisterCallback() {
@Override
public void onSuccess(AccountResult bindAccountResult) {
//登录成功
}
@Override
public void onError(BaseResult error) {
//登录失败
}
});
/**
* Facebook登录
* @param activity 当前Activity
*/
public static void facebookLogin(Activity activity)
FacebookSocialHelper.facebookLogin(MainActivity.this);
/**
* Google帐号登录
* @param activity 当前Activity
*/
public static void googleLogin(Activity activity)
GoogleSocialHelper.googleLogin(MainActivity.this);
Facebook和Google登录,切换帐号结果回调
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
...
if (ngamesSdk != null && ngamesSdk.handleActivityResult(requestCode, resultCode, data)) {
return;
}
if (requestCode == Const.THIRD_LOGIN_REQUEST_CODE) {
switch (resultCode) {
case Const.INTENT_RESULT_OK:
//登录成功
AccountResult loginUser = (AccountResult) data.getSerializableExtra(Const.LOGIN_USER);
logText.setText("user type:" + loginUser.getAccountType() + " ,user id=" + loginUser.getData().getId());
break;
case Const.INTENT_RESULT_CANCELED:
//取消登录
Toast.makeText(MainActivity.this, "canceled", Toast.LENGTH_SHORT).show();
break;
case Const.INTENT_RESULT_ERROR:
//登录失败
Toast.makeText(MainActivity.this, "error", Toast.LENGTH_SHORT).show();
break;
default:
logText.setText("resultCode=" + resultCode);
break;
}
return;
} else if (requestCode == Const.THIRD_ACCOUNT_MANAGER_REQUEST_CODE) {
//帐号管理回调
switch (resultCode) {
case Const.INTENT_RESULT_CHANGE_ACCOUNT_OK:
//切换帐号成功
Log.d("NgamesSdk", "切换帐号成功");
AccountResult changeUser = (AccountResult) data.getSerializableExtra(Const.LOGIN_USER);
logText.setText("切换帐号 . user type:" + changeUser.getAccountType() + " ,user id=" + changeUser.getData().getId());
break;
}
}
...
super.onActivityResult(requestCode, resultCode, data);
}
//设置服务器ID
ngamesSdk.setSid(mServerId);
//设置角色名称
ngamesSdk.setRoleName(mRoleName);
//显示悬浮框(自己决定是否显示)
ngamesSdk.showPop();