Coder Social home page Coder Social logo

shivampip / higoogle Goto Github PK

View Code? Open in Web Editor NEW
7.0 2.0 3.0 834 KB

Add Google Sign In Option with few lines on code

Home Page: https://shivam301296.github.io/HiGoogle/

License: GNU General Public License v3.0

Java 100.00%
googlesignin googleapi signin madeeasy google-cloud google android-library android-studio android

higoogle's Introduction

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.

higoogle's People

Contributors

shivampip avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

higoogle's Issues

Android Google Sign In Nothing Happen If Use Add Account

Here's the case:

Press Sign In Button
Add Account
Insert Email and Password
Waiting Checking Info
Screen like a black hover, and nothing happened
pressed sign in button again i get the data
I have already put my SHA-1 and use the correct server_client_id.
If i have already signed in user, the google sign in works, the problem only at first time login with no account or create account.

Any suggestion for this problem ? Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.