setViewForPopUp(view) google api (11.6.0) google 玩签到
setViewForPopUp(view) google api (11.6.0) google play sign in
所以 google 玩签到的方式发生了变化,很久以前我实现签到时它是 throw GoogleApiClient
但现在不同了它的 throw GoogleSignInClient
我不知道不知道如何在用户登录或解锁成就时设置弹出视图。即使在 google 文档中对此没有很好的解释,所以任何人都知道它 post 你的回答提前谢谢
//google variable
private static int RC_SIGN_IN = 9001;
private static final int RC_ACHIEVEMENT_UI = 9003;
GoogleApiClient googleApiClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void SignIn(View view) {
GoogleSignInClient signInClient = GoogleSignIn.getClient(this,
GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN);
Intent intent = signInClient.getSignInIntent();
startActivityForResult(intent, RC_SIGN_IN);
}
private void signInSilently() {
GoogleSignInClient signInClient = GoogleSignIn.getClient(this,
GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN);
signInClient.silentSignIn().addOnCompleteListener(this,
new OnCompleteListener<GoogleSignInAccount>() {
@Override
public void onComplete(@NonNull Task<GoogleSignInAccount> task) {
if (task.isSuccessful()) {
// The signed in account is stored in the task's result.
GoogleSignInAccount signedInAccount = task.getResult();
} else {
// Player will need to sign-in explicitly using via UI
}
}
});
}
@Override
protected void onResume() {
super.onResume();
signInSilently();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Toast.makeText(MainActivity.this, String.valueOf(requestCode), Toast.LENGTH_SHORT).show();
if (requestCode == RC_SIGN_IN) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
Log.d("fuck", String.valueOf(result));
// Toast.makeText(MainActivity.this,String.valueOf(result),Toast.LENGTH_SHORT).show();
if (result.isSuccess()) {
// The signed in account is stored in the result.
Toast.makeText(MainActivity.this, "Succesfull", Toast.LENGTH_SHORT).show();
GoogleSignInAccount signedInAccount = result.getSignInAccount();
} else {
String message = result.getStatus().getStatusMessage();
if (message == null || message.isEmpty()) {
message = getString(R.string.signin_other_error);
}
new AlertDialog.Builder(this).setMessage(message)
.setNeutralButton(android.R.string.ok, null).show();
}
}
}
public void achievement(View view) {
Games.getAchievementsClient(this, GoogleSignIn.getLastSignedInAccount(this))
.getAchievementsIntent()
.addOnSuccessListener(new OnSuccessListener<Intent>() {
@Override
public void onSuccess(Intent intent) {
startActivityForResult(intent, RC_ACHIEVEMENT_UI);
}
});
}
public void unlock(View view) {
Games.getAchievementsClient(this, GoogleSignIn.getLastSignedInAccount(this))
.unlock(getString(R.string.achievement_newbie));
}
好的,我试了几次后自己得到了答案
您可以做的是在成功登录后 task.getResult()
将 return GoogleSignInAccount
对象传递给 getGamesClient
方法,该方法将 return 一个 GamesClient
对象并使用该对象可以调用 setViewForPopups
方法。下面是明码
private void signInSilently() {
GoogleSignInClient signInClient = GoogleSignIn.getClient(this,
GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN);
signInClient.silentSignIn().addOnCompleteListener(this,
new OnCompleteListener<GoogleSignInAccount>() {
@Override
public void onComplete(@NonNull Task<GoogleSignInAccount> task) {
if (task.isSuccessful()) {
// The signed in account is stored in the task's result.
GoogleSignInAccount signedInAccount = task.getResult();
GamesClient gamesClient =Games.getGamesClient(MainActivity.this,signedInAccount);
gamesClient.setViewForPopups(findViewById(R.id.textview));
} else {
// Player will need to sign-in explicitly using via UI
}
}
});
}
所以 google 玩签到的方式发生了变化,很久以前我实现签到时它是 throw GoogleApiClient
但现在不同了它的 throw GoogleSignInClient
我不知道不知道如何在用户登录或解锁成就时设置弹出视图。即使在 google 文档中对此没有很好的解释,所以任何人都知道它 post 你的回答提前谢谢
//google variable
private static int RC_SIGN_IN = 9001;
private static final int RC_ACHIEVEMENT_UI = 9003;
GoogleApiClient googleApiClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void SignIn(View view) {
GoogleSignInClient signInClient = GoogleSignIn.getClient(this,
GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN);
Intent intent = signInClient.getSignInIntent();
startActivityForResult(intent, RC_SIGN_IN);
}
private void signInSilently() {
GoogleSignInClient signInClient = GoogleSignIn.getClient(this,
GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN);
signInClient.silentSignIn().addOnCompleteListener(this,
new OnCompleteListener<GoogleSignInAccount>() {
@Override
public void onComplete(@NonNull Task<GoogleSignInAccount> task) {
if (task.isSuccessful()) {
// The signed in account is stored in the task's result.
GoogleSignInAccount signedInAccount = task.getResult();
} else {
// Player will need to sign-in explicitly using via UI
}
}
});
}
@Override
protected void onResume() {
super.onResume();
signInSilently();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Toast.makeText(MainActivity.this, String.valueOf(requestCode), Toast.LENGTH_SHORT).show();
if (requestCode == RC_SIGN_IN) {
GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
Log.d("fuck", String.valueOf(result));
// Toast.makeText(MainActivity.this,String.valueOf(result),Toast.LENGTH_SHORT).show();
if (result.isSuccess()) {
// The signed in account is stored in the result.
Toast.makeText(MainActivity.this, "Succesfull", Toast.LENGTH_SHORT).show();
GoogleSignInAccount signedInAccount = result.getSignInAccount();
} else {
String message = result.getStatus().getStatusMessage();
if (message == null || message.isEmpty()) {
message = getString(R.string.signin_other_error);
}
new AlertDialog.Builder(this).setMessage(message)
.setNeutralButton(android.R.string.ok, null).show();
}
}
}
public void achievement(View view) {
Games.getAchievementsClient(this, GoogleSignIn.getLastSignedInAccount(this))
.getAchievementsIntent()
.addOnSuccessListener(new OnSuccessListener<Intent>() {
@Override
public void onSuccess(Intent intent) {
startActivityForResult(intent, RC_ACHIEVEMENT_UI);
}
});
}
public void unlock(View view) {
Games.getAchievementsClient(this, GoogleSignIn.getLastSignedInAccount(this))
.unlock(getString(R.string.achievement_newbie));
}
好的,我试了几次后自己得到了答案
您可以做的是在成功登录后 task.getResult()
将 return GoogleSignInAccount
对象传递给 getGamesClient
方法,该方法将 return 一个 GamesClient
对象并使用该对象可以调用 setViewForPopups
方法。下面是明码
private void signInSilently() {
GoogleSignInClient signInClient = GoogleSignIn.getClient(this,
GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN);
signInClient.silentSignIn().addOnCompleteListener(this,
new OnCompleteListener<GoogleSignInAccount>() {
@Override
public void onComplete(@NonNull Task<GoogleSignInAccount> task) {
if (task.isSuccessful()) {
// The signed in account is stored in the task's result.
GoogleSignInAccount signedInAccount = task.getResult();
GamesClient gamesClient =Games.getGamesClient(MainActivity.this,signedInAccount);
gamesClient.setViewForPopups(findViewById(R.id.textview));
} else {
// Player will need to sign-in explicitly using via UI
}
}
});
}