Why does exception occur when I try to login with google?

175 Views Asked by At

I tried to implement login with google but it always throws exception and toast not logged in

package com.inshortsapk.inshorts;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.google.android.gms.auth.api.signin.GoogleSignIn;
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
import com.google.android.gms.auth.api.signin.GoogleSignInClient;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import com.google.android.gms.common.api.ApiException;
import com.google.android.gms.tasks.Task;

public class my_login extends AppCompatActivity {
    GoogleSignInOptions gso;
    GoogleSignInClient gsc;
    Button btnLogin;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_login);
        gso=new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_GAMES_SIGN_IN).requestEmail().build();
        gsc= GoogleSignIn.getClient(this,gso);

        btnLogin=findViewById(R.id.btnLogin);
        GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this);
        //(account);
        btnLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               // Toast.makeText(my_login.this, "mylogin click", Toast.LENGTH_SHORT).show();
                signIn();
            }
        });
    }
    public void signIn(){
        Intent signInIntent=gsc.getSignInIntent();
         startActivityForResult(signInIntent,1000);


    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode,  Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode==1000)
        {
            Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
            try {
                Toast.makeText(this, "TRY 11", Toast.LENGTH_SHORT).show();
              
                task.getResult(ApiException.class);

                Toast.makeText(this, "TRY 12", Toast.LENGTH_SHORT).show();


                Intent intent=new Intent(this,MainActivity.class);
                startActivity(intent);
            } catch (ApiException e) {

                //not loged in
                Toast.makeText(this, "Not Logged In", Toast.LENGTH_SHORT).show();
                e.printStackTrace();
            }
        }
    }
}

What I need is that I need to logged in user when he click on login button and switch to another activity is called mainactivity.java I tried as many way as possible but it threw a exception every time.

Here is my logcat

    2023-03-20 14:13:33.171 17566-17566/com.inshortsapk.inshorts D/IS_CTS_MODE: false
2023-03-20 14:13:33.171 17566-17566/com.inshortsapk.inshorts D/MULTI_WINDOW_SWITCH_ENABLED: false
2023-03-20 14:13:33.173 17566-17566/com.inshortsapk.inshorts D/DecorView[]: getWindowModeFromSystem  windowmode is 1
2023-03-20 14:13:33.265 17566-17566/com.inshortsapk.inshorts D/DecorView[]: onWindowFocusChanged hasWindowFocus false
2023-03-20 14:13:33.516 17566-17566/com.inshortsapk.inshorts D/CompatibilityChangeReporter: Compat change id reported: 147798919; UID 10603; state: ENABLED
2023-03-20 14:13:33.532 17566-17566/com.inshortsapk.inshorts W/System.err: com.google.android.gms.common.api.ApiException: 10: 
2023-03-20 14:13:33.532 17566-17566/com.inshortsapk.inshorts W/System.err:     at com.google.android.gms.common.internal.ApiExceptionUtil.fromStatus(com.google.android.gms:play-services-base@@18.0.1:3)
2023-03-20 14:13:33.532 17566-17566/com.inshortsapk.inshorts W/System.err:     at com.google.android.gms.auth.api.signin.GoogleSignIn.getSignedInAccountFromIntent(com.google.android.gms:play-services-auth@@20.4.1:3)
2023-03-20 14:13:33.533 17566-17566/com.inshortsapk.inshorts W/System.err:     at com.inshortsapk.inshorts.my_login.onActivityResult(my_login.java:54)
2023-03-20 14:13:33.533 17566-17566/com.inshortsapk.inshorts W/System.err:     at android.app.Activity.dispatchActivityResult(Activity.java:8579)
2023-03-20 14:13:33.533 17566-17566/com.inshortsapk.inshorts W/System.err:     at android.app.ActivityThread.deliverResults(ActivityThread.java:5445)
2023-03-20 14:13:33.533 17566-17566/com.inshortsapk.inshorts W/System.err:     at android.app.ActivityThread.handleSendResult(ActivityThread.java:5491)
2023-03-20 14:13:33.533 17566-17566/com.inshortsapk.inshorts W/System.err:     at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:54)
2023-03-20 14:13:33.533 17566-17566/com.inshortsapk.inshorts W/System.err:     at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
2023-03-20 14:13:33.533 17566-17566/com.inshortsapk.inshorts W/System.err:     at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
2023-03-20 14:13:33.533 17566-17566/com.inshortsapk.inshorts W/System.err:     at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
2023-03-20 14:13:33.533 17566-17566/com.inshortsapk.inshorts W/System.err:     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2284)
2023-03-20 14:13:33.533 17566-17566/com.inshortsapk.inshorts W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:106)
2023-03-20 14:13:33.533 17566-17566/com.inshortsapk.inshorts W/System.err:     at android.os.Looper.loopOnce(Looper.java:210)
2023-03-20 14:13:33.533 17566-17566/com.inshortsapk.inshorts W/System.err:     at android.os.Looper.loop(Looper.java:299)
2023-03-20 14:13:33.533 17566-17566/com.inshortsapk.inshorts W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:8302)
2023-03-20 14:13:33.533 17566-17566/com.inshortsapk.inshorts W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
2023-03-20 14:13:33.533 17566-17566/com.inshortsapk.inshorts W/System.err:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:556)
2023-03-20 14:13:33.533 17566-17566/com.inshortsapk.inshorts W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1037)
2023-03-20 14:13:33.541 17566-17566/com.inshortsapk.inshorts D/DecorView[]: onWindowFocusChanged hasWindowFocus false
2023-03-20 14:13:33.541 17566-17566/com.inshortsapk.inshorts D/DecorView[]: onWindowFocusChanged hasWindowFocus true

As well as when I build my app then it will through this error also

 open libmigui.so failed! dlopen - dlopen failed: library "libmigui.so" not found
1

There are 1 best solutions below

0
vatsal mangukiya On BEST ANSWER

In onCreate method i should use DEFAULT_SIGN_IN instead of DEFAULT_GAMES_SIGN_IN

 gso=new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).requestEmail().build();