Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • How to Enable GMail Login Feature Within Android Application in 4 Easy Steps

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 1
    • 0
    • 523
    Comment on it

    You must have seen many applications and websites provides option to login/signup using Gmail, Facebook, twitter etc. And In my previous tutorial, I had explained Integrate Twitter Login for Your Android App in same way you can also enable Gmail login feature within your android app.


    So, If you are willing to add gmail login within your app then please go through the steps mentioned below:-


    Step 1) You need to add dependency compile line in your build.gradle file

    compile ''

    sync your project after adding this.


    Step 2) Now for authentication you need to create a new project in google portal so that gmail login can be used within your application , so for this please go to the link mentioned below

    after creating new app on google domain the google domain will provide a   google-services.json file place this file inside your app folder


    Step 3) Now add the gmail login button code in your activity layout(xml) file.

            android:layout_height="wrap_content" />


    Step 4) Now add the below code in your Activity and all done

    public class LoginActivity extends AppCompatActivity implements GoogleApiClient.OnConnectionFailedListener {
        GoogleApiClient mGoogleApiClient;
        private int RC_SIGN_IN=1001;
        protected void onCreate(Bundle savedInstanceState) {
            GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            mGoogleApiClient = new GoogleApiClient.Builder(this)
                    .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
                    .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            SignInButton signInButton = (SignInButton) findViewById(;
            signInButton.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
            // Pass the activity result to the login button.
    //        loginButton.onActivityResult(requestCode, resultCode, data);
            if (requestCode == RC_SIGN_IN) {
                GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
        private void handleSignInResult(GoogleSignInResult result) {
            if (result.isSuccess()) {
                // Signed in successfully, show authenticated UI.
                Toast.makeText(this, "Yee" +
                        " we are in", Toast.LENGTH_SHORT).show();
                GoogleSignInAccount acct = result.getSignInAccount();
            } else {
                // Signed out, show unauthenticated UI.
        private void signIn() {
            Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
            startActivityForResult(signInIntent, RC_SIGN_IN);
        public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {


    How to Enable GMail Login Feature Within Android Application in 4 Easy Steps

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: