Skip to content

shivampip/HiGoogle

Repository files navigation

Hi Google- Google SignIn Made Easy

Hi Google is a powerful & easy to use lib for Android. It runs on API level 14 and upwards. This library helps you to add Google Sign In option in your app with few lines of code. and also Guide you to the process of registering your app to Google Cloud.

A few line of code can add a Google Sign In in your app.

Setup

Gradle dependency (recommended)

  • Add the following to your project level build.gradle:
allprojects {
	repositories {
		maven { url "https://jitpack.io" }
	}
}
  • Add this to your app build.gradle:
dependencies {
	compile 'com.github.shivam301296:HiGoogle:1.0.0'
}

Or use Maven

  • Add the following to the <repositories> section of your pom.xml:
<repository>
       <id>jitpack.io</id>
       <url>https://jitpack.io</url>
</repository>
  • Add the following to the <dependencies> section of your pom.xml:
<dependency>
       <groupId>com.github.shivam301296</groupId>
         <artifactId>HiGoogle</artifactId>
         <version>1.0.0</version>
</dependency>

Documentation

Adding Google SignIn button in your app involves two tasks

  1. Register your app on Google Cloud Plateform
  2. Programming in Android Studio or else

Register Your App on Google Cloud

(1) Go to this link

(2) Fill your app name and package name

(3) Next it will ask for SHA1 Certificate. For getting SHA1 Certificate for your app, In your Android Studio Right Side (vertical) Gradle> Project Name> Project Name(root)> Tasks> android> signingReport (double click)

(4) It will generate Signin report. Copy the SHA1 Certificate from it

(5) Fill this SHA1 Certificate in the form and click Generate Configuration file

(6) Download 'google-services.json' file

(7) Paste this file in Android Studio First Switch to Project View Project Name> app> (Paste here)

DONE

IN YOUR APP

Add SignIn Button in design xml file

<com.google.android.gms.common.SignInButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/googleSignInB"
        android:layout_centerInParent="true"/>

In your Activity class

(1) Define hiGoogle globally

HiGoogle hiGoogle;
SignInButton signInButton;

(2) Initilize it in onCreate method

signInButton = findViewById(R.id.googleSignInB);
hiGoogle = new HiGoogle(this, this);  			//Normally recommanded
hiGoogle = new HiGoogle(this, this, accessToken);	//If require Token id 

(3) On signIn button click, call signIn method

signInButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                hiGoogle.signIn(new OnLoginListener() {
                    @Override
                    public void onSuccess(GoogleSignInAccount account) {
                        display("Sign in Successful");
                        tv.setText("SignIn Successful");
                        tv.append("\nEmail:- " + account.getEmail());
                        tv.append("\nName:- " + account.getDisplayName());
                        tv.append("\nID:- "+account.getId());
                        //Need to add Glide Dependency and INTERNET permission
                        //Glide.with(getApplicationContext()).load(account.getPhotoUrl()).into(profileIv);
                    }
                    @Override
                    public void onFailed(String why) {
                        display("Sign in failed");
                        tv.setText("Sign in failed due to:- \n"+why);
                    }
                });
            }
        });

(4) Override onActivityResult in your activity and call hiGoogle.fromActivityResult(...) method from inside

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        hiGoogle.fromActivityResult(requestCode, data);
    }

DONE

Troubleshoot

(1) Problem while running applicaiton (Change from signingReport to Run)

==>

(2) Not able to find package name (Go to AndroidManifest.xml)

Works on

  • Android 4.0.1 (Ice Cream Sandwich) and above.

Permissions

  • Does not require any special permission

Built With

Third party libraries

  • No external library dependency

Authors

Version

  • Version 1.0.0

License

Sorry Albert Einstein Ji

You had said- “Make things as simple as possible, but no simpler.”

But this lib is simpler.