Android SDK_登录相关功能
Last updated
Last updated
import io.gamepot.channel.GamePotChannel;
import io.gamepot.channel.GamePotChannelType;
import io.gamepot.channel.facebook.GamePotFacebook;
import io.gamepot.channel.google.signin.GamePotGoogleSignin;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// 请先调用setup API。
GamePot.getInstance().setup(getApplicationContext());
...
// 请按照要使用登录的渠道调用addChannel。默认包括Guest方式。
// Google Login初始化
GamePotChannel.getInstance().addChannel(this, GamePotChannelType.GOOGLE, new GamePotGoogleSignin());
// Facebook Login初始化
GamePotChannel.getInstance().addChannel(this, GamePotChannelType.FACEBOOK, new GamePotFacebook());
...
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
GamePotChannel.getInstance().onActivityResult(this, requestCode, resultCode, data);
}
@Override
protected void onDestroy() {
super.onDestroy();
GamePotChannel.getInstance().onDestroy();
}
}=import io.gamepot.channel.GamePotChannel;
import io.gamepot.channel.GamePotChannelListener;
import io.gamepot.channel.GamePotChannelType;
import io.gamepot.channel.GamePotUserInfo;
import io.gamepot.common.GamePotError;
// 定义登录类型
// GamePotChannelType.GOOGLE: Google
// GamePotChannelType.FACEBOOK: Facebook
// GamePotChannelType.NAVER: NAVER
// GamePotChannelType.LINE: LINE
// GamePotChannelType.APPLE: Apple
// GamePotChannelType.GUEST: Guest
// 点击Google登录按钮时呼叫
GamePotChannel.getInstance().login(this, GamePotChannelType.GOOGLE, new GamePotChannelListener<GamePotUserInfo>() {
@Override
public void onCancel() {
// 用户取消登录的情况
}
@Override
public void onSuccess(GamePotUserInfo userinfo) {
// 登录成功。请根据游戏逻辑处理。
// userinfo.getMemberid():会员固有ID
}
@Override
public void onFailure(GamePotError error) {
// 登录失败。请使用error.getMessage显示错误消息。
}
});GamePot.getInstance().getMemberId();android {
defaultConfig {
...
resValue "string", "gamepot_naver_clientid", "xxxxxxxx" // 从Naver开发者控制台获取
resValue "string", "gamepot_naver_secretid", "xxx" // 从Line开发者控制台获取
}
}
dependencies {
...
compile(name: 'gamepot-channel-naver', ext: 'aar')
...
}import io.gamepot.channel.GamePotChannel;
import io.gamepot.channel.GamePotChannelType;
import io.gamepot.channel.naver.GamePotNaver;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
GamePotChannel.getInstance().addChannel(this, GamePotChannelType.NAVER, new GamePotNaver());
}GamePotChannel.getInstance().login(this, GamePotChannelType.NAVER, new GamePotAppStatusChannelListener<GamePotUserInfo>() {
...
});android {
defaultConfig {
...
resValue "string", "gamepot_line_channelid","00000000" // 从Line开发者控制台获取
}
}
dependencies {
...
compile(name: 'gamepot-channel-line', ext: 'aar')
compile(name: 'line-sdk-4.0.10', ext: 'aar')
...
}import io.gamepot.channel.GamePotChannel;
import io.gamepot.channel.GamePotChannelType;
import io.gamepot.channel.line.GamePotLine;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
GamePotChannel.getInstance().addChannel(this, GamePotChannelType.LINE, new GamePotLine());
}GamePotChannel.getInstance().login(this, GamePotChannelType.LINE, new GamePotAppStatusChannelListener<GamePotUserInfo>() {
...
});dependencies {
...
compile(name: 'gamepot-channel-apple-signin', ext: 'aar')
...
}import io.gamepot.channel.GamePotChannel;
import io.gamepot.channel.GamePotChannelType;
import io.gamepot.channel.apple.signin.GamePotAppleSignin;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
GamePotChannel.getInstance().addChannel(this, GamePotChannelType.APPLE, new GamePotAppleSignin());
}GamePotChannel.getInstance().login(this, GamePotChannelType.APPLE, new GamePotAppStatusChannelListener<GamePotUserInfo>() {
...
});import io.gamepot.channel.GamePotChannel;
import io.gamepot.channel.GamePotChannelListener;
import io.gamepot.channel.GamePotChannelType;
import io.gamepot.channel.GamePotUserInfo;
import io.gamepot.common.GamePotError;
// 传递用户最后登录信息的API
final GamePotChannelType lastLoginType = GamePotChannel.getInstance().getLastLoginType();
if(lastLoginType != GamePotChannelType.NONE) {
// 以最后一次登录的类型登录的方式。
GamePotChannel.getInstance().login(this, lastLoginType, new GamePotChannelListener<GamePotUserInfo>() {
@Override
public void onCancel() {
// 用户取消登录的情况
}
@Override
public void onSuccess(GamePotUserInfo info) {
// 自动登录成功。请根据游戏逻辑进行处理。
}
@Override
public void onFailure(GamePotError error) {
// 自动登录失败。请使用error.getMessage()显示错误消息。
}
});
}
else
{
// 首次运行游戏或已退出登录的状态。请跳转到可进行登录的登录界面。
}import io.gamepot.channel.GamePotChannel;
import io.gamepot.common.GamePotCommonListener;
import io.gamepot.common.GamePotError;
GamePotChannel.getInstance().logout(this, new GamePotCommonListener() {
@Override
public void onSuccess() {
// 成功退出登录。请跳转至初始界面。
}
@Override
public void onFailure(GamePotError error) {
// 退出登录失败。请使用error.getMessage()显示错误消息。
}
});import io.gamepot.channel.GamePotChannel;
import io.gamepot.common.GamePotCommonListener;
import io.gamepot.common.GamePotError;
GamePotChannel.getInstance().deleteMember(this, new GamePotCommonListener() {
@Override
public void onSuccess() {
// 会员注销成功。请跳转至初始界面。
}
@Override
public void onFailure(GamePotError error) {
// 会员注销失败。请使用error.getMessage()显示错误消息。
}
});