OnActivityResult已弃用,如何处理Google Sign in Fragment for Android(Java)?

onActivityResult deprecated, how to handle google signin in fragment for android(Java)?(OnActivityResult已弃用,如何处理Google Sign in Fragment for Android(Java)?)

本文介绍了OnActivityResult已弃用,如何处理Google Sign in Fragment for Android(Java)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

    @Override **//depricated**
    public void onActivityResult(int requestCode, int resultCode, @Nullable @org.jetbrains.annotations.Nullable Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
         if (resultCode == Activity.RESULT_OK) {
            if (requestCode == REQUEST_OAUTH_REQUEST_CODE) {
                insertAndVerifySession();
            }
        }
    }

GoogleSignIn.requestPermissions(
                fragment,
                REQUEST_OAUTH_REQUEST_CODE,
                GoogleSignIn.getLastSignedInAccount(context),
                fitnessOptions);

片段中GoogleSignIn的onActivityResult的替代方案是什么?

推荐答案

如here所述,您可以通过调用getSignInIntent

获取登录意图
ActivityResultLauncher<Intent> exampleActivityResult= registerForActivityResult(
new ActivityResultContracts.StartActivityForResult(),
new ActivityResultCallback<ActivityResult>() {
    @Override
    public void onActivityResult(ActivityResult result) {
        if (result.getResultCode() == Activity.RESULT_OK) {
            Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(result.getData());
handleSignInResult(task);
        }
    }
});



//call
   exampleActivityResult.launch(mGoogleSignInClient.getSignInIntent());

更新-30-11-2021

这里是new method by google!

这篇关于OnActivityResult已弃用,如何处理Google Sign in Fragment for Android(Java)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:OnActivityResult已弃用,如何处理Google Sign in Fragment for Android(Java)?

基础教程推荐