首次登录Google Play后,欢迎弹出窗口无法正常工作

问题描述

在应用程序中首次登录Google Play后,欢迎弹出窗口无法正常工作。但是当我之后自动登录时,它可以正常工作。

onActivityResult函数中的以下语法无法正常工作。

Games.getGamesClient(getContext(),mSignedInAccount).setViewForPopups(getWindow()。getDecorView()。findViewById(android.R.id.content));

我要使弹出窗口即使在首次登录后也能正常工作。

private GoogleSignInClient mGoogleSignInClient = null;
private GoogleSignInAccount mSignedInAccount = null;
private GamesClient mGamesClient = null;
private GoogleSignInOptions mSignInOptions =null;

Boolean bGoogleLogin = false;

private static final int RC_SIGN_IN = 9001;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.setEnableVirtualButton(false);
    super.onCreate(savedInstanceState);

 
    mSignInOptions = GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN;


    mGoogleSignInClient = GoogleSignIn.getClient(this,new GoogleSignInOptions.Builder(mSignInOptions).build());

    
}



@Override
protected void onActivityResult(int requestCode,int resultCode,Intent data) {
    super.onActivityResult(requestCode,resultCode,data);
        bGoogleLogin = true;
        if (requestCode == RC_SIGN_IN) {
            GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
            if (result.isSuccess()) {
                mSignedInAccount = result.getSignInAccount();



                Toast.makeText(getApplicationContext(),"Signed In",Toast.LENGTH_SHORT).show();


                Games.getGamesClient(getContext(),mSignedInAccount).setViewForPopups(getWindow().getDecorView().findViewById(android.R.id.content));

            } else {
                String message = result.getStatus().getStatusMessage();
                if (message == null || message.isEmpty()) {
                    message = "Error";
                }
                Toast.makeText(getApplicationContext(),"Sign In Failed,please check internet connection and restart the app to use achievements.",Toast.LENGTH_LONG).show();

            }
        }
}

@Override
protected void onResume() {
    super.onResume();
    this.signInSilently();


}

public void signInSilently() {


    GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this);

    if (GoogleSignIn.hasPermissions(account,mSignInOptions.getScopeArray())) {
        // Already signed in.
        // The signed in account is stored in the 'account' variable.

        Toast.makeText(getApplicationContext(),"Signed In Already",Toast.LENGTH_SHORT).show();

        mSignedInAccount = account;



        Games.getGamesClient(getContext(),mSignedInAccount).setViewForPopups(getWindow().getDecorView().findViewById(android.R.id.content));



    } else {



        mGoogleSignInClient.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 googleSignInAccount = task.getResult();

                                    if (mSignedInAccount != googleSignInAccount) {

                                        mSignedInAccount = googleSignInAccount;


                                        Toast.makeText(getApplicationContext(),"Silent Signed In",Toast.LENGTH_SHORT).show();
                                    }

                                } else {
                                    if(bGoogleLogin == false) {
                                        startActivityForResult(mGoogleSignInClient.getSignInIntent(),RC_SIGN_IN);
                                    }
                                }
                            }
                        });
    }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...