✅ How to sign into google account android ⭐️⭐️⭐️⭐️⭐️

5/5 - (1 bình chọn)

Sign in with your phone instead of a password

If you don’t want to enter your password each time you sign in to your Google Account, you can get a Google prompt sent to your phone instead. 

Google prompts are push notifications that help confirm it’s you. When you turn on the option to sign in with your phone, you also add another way to prove it’s your account if you forget your password.

Set up your phone

Important: This feature is not available if you have 2-step verification enabled on your account.

To sign in with your phone instead of a password, you need an Android phone with a screen lock.

  1. Go to your Google Account.
  2. In the navigation panel, tap Security.
  3. Under “Signing in to Google,” tap Use your phone to sign in -> Set it up.
    You may need to sign in.
  4. Follow the on-screen steps.
    1. If your phone doesn’t have a screen lock, tap Add a screen lock. Follow the on-screen steps.

Tip: You’ll get prompts on any eligible devices that are signed in to your Google account.

Sign in with your phone

  1. When you sign in to your Google Account, enter your email address or phone number.
  2. Tap Next. You’ll get a reminder to check your phone.
  3. Unlock your Android phone.
  4. On the “Trying to sign in?” prompt, tap Yes.
    • If your phone isn’t nearby, you can select Use password or other options on the sign-in screen.

Start Integrating Google Sign-In into Your Android App

Before you can start integrating Google Sign-In in your own app, you must configure a Google API Console project and set up your Android Studio project. The steps on this page do just that. The next steps then describe how to integrate Google Sign-In into your app.

Prerequisites

Google Sign-In for Android has the following requirements:

  • A compatible Android device that runs Android 4.4 or newer and includes the Google Play Store or an emulator with an AVD that runs the Google APIs platform based on Android 4.2.2 or newer and has Google Play services version 15.0.0 or newer.
  • The latest version of the Android SDK, including the SDK Tools component. The SDK is available from the Android SDK Manager in Android Studio.
  • A project configured to compile against Android 4.4 (KitKat) or newer.

This guide is written for users of Android Studio, which is the recommended development environment.

Add Google Play services

In your project’s top-level build.gradle file, ensure that Google’s Maven repository is included:

allprojects {
    repositories {
        google()

        // If you're using a version of Gradle lower than 4.1, you must instead use:
        // maven {
        //     url 'https://maven.google.com'
        // }
    }
}

Then, in your app-level build.gradle file, declare Google Play services as a dependency:

apply plugin: 'com.android.application'
    ...

    dependencies {
        implementation 'com.google.android.gms:play-services-auth:20.3.0'
    }

Configure a Google API Console project

To configure a Google API Console project, click the button below, and specify your app’s package name when prompted. You will also need to provide the SHA-1 hash of your signing certificate. See Authenticating Your Client for information.

Configure a project

Get your backend server’s OAuth 2.0 client ID

If your app authenticates with a backend server or accesses Google APIs from your backend server, you must get the OAuth 2.0 client ID that was created for your server. To find the OAuth 2.0 client ID:

  1. Open the Credentials page in the API Console.
  2. The Web application type client ID is your backend server’s OAuth 2.0 client ID.

Note: If you haven’t recently created a new Android client, you might not have a Web application type client ID. You can create one by opening the Credentials page and clicking New credentials > OAuth client ID.

Pass this client ID to the requestIdToken or requestServerAuthCode method when you create the GoogleSignInOptions object.

Next steps

Now that you have configured a Google API Console project and set up your Android Studio project, you can integrate Google Sign-In into your app.

Integrating Google Sign-In into Your Android App

To integrate Google Sign-In into your Android app, configure Google Sign-In and add a button to your app’s layout that starts the sign-in flow.

Before you begin

Configure a Google API Console project and set up your Android Studio project.

Configure Google Sign-in and the GoogleSignInClient object

In your sign-in activity’s onCreate method, configure Google Sign-In to request the user data required by your app. For example, to configure Google Sign-In to request users’ ID and basic profile information, create a GoogleSignInOptions object with the DEFAULT_SIGN_IN parameter. To request users’ email addresses as well, create the GoogleSignInOptions object with the requestEmail option.

// Configure sign-in to request the user's ID, email address, and basic
// profile. ID and basic profile are included in DEFAULT_SIGN_IN.
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
        .requestEmail()
        .build();

Configure Google Sign-in and the GoogleSignInClient object

In your sign-in activity’s onCreate method, configure Google Sign-In to request the user data required by your app. For example, to configure Google Sign-In to request users’ ID and basic profile information, create a GoogleSignInOptions object with the DEFAULT_SIGN_IN parameter. To request users’ email addresses as well, create the GoogleSignInOptions object with the requestEmail option.

// Configure sign-in to request the user's ID, email address, and basic
// profile. ID and basic profile are included in DEFAULT_SIGN_IN.
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
        .requestEmail()
        .build();

Check for an existing signed-in user

In your activity's onStart method, check if a user has already signed in to your app with Google.

// Check for existing Google Sign In account, if the user is already signed in
// the GoogleSignInAccount will be non-null.
GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this);
updateUI(account);

If GoogleSignIn.getLastSignedInAccount returns a GoogleSignInAccount object (rather than null), the user has already signed in to your app with Google. Update your UI accordingly—that is, hide the sign-in button, launch your main activity, or whatever is appropriate for your app.

If GoogleSignIn.getLastSignedInAccount returns null, the user has not yet signed in to your app with Google. Update your UI to display the Google Sign-in button.
Note: If you need to detect changes to a user's auth state that happen outside your app, such as access token or ID token revocation, or to perform cross-device sign-in, you might also call GoogleSignInClient.silentSignIn when your app starts.

Add the Google Sign-in button to your app

The standard Google sign-in button Add the SignInButton in your application's layout:

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

Optional: If you are using the default sign-in button graphic instead of providing your own sign-in button assets, you can customize the button’s size with the setSize method.

// Set the dimensions of the sign-in button.
SignInButton signInButton = findViewById(R.id.sign_in_button);
signInButton.setSize(SignInButton.SIZE_STANDARD);

In the Android activity (for example, in the onCreate method), register your button’s OnClickListener to sign in the user when clicked:

findViewById(R.id.sign_in_button).setOnClickListener(this);

Start the sign-in flow

In the activity’s onClick method, handle sign-in button taps by creating a sign-in intent with the getSignInIntent method, and starting the intent with startActivityForResult.

@Override
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.sign_in_button:
            signIn();
            break;
        // ...
    }
}
private void signIn() {
    Intent signInIntent = mGoogleSignInClient.getSignInIntent();
    startActivityForResult(signInIntent, RC_SIGN_IN);
}

Starting the intent prompts the user to select a Google account to sign in with. If you requested scopes beyond profile, email, and openid, the user is also prompted to grant access to the requested resources.

After the user signs in, you can get a GoogleSignInAccount object for the user in the activity’s onActivityResult method.

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    // Result returned from launching the Intent from GoogleSignInClient.getSignInIntent(...);
    if (requestCode == RC_SIGN_IN) {
        // The Task returned from this call is always completed, no need to attach
        // a listener.
        Task<GoogleSignInAccount> task = GoogleSignIn.getSignedInAccountFromIntent(data);
        handleSignInResult(task);
    }
}

The GoogleSignInAccount object contains information about the signed-in user, such as the user’s name.

private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {
    try {
        GoogleSignInAccount account = completedTask.getResult(ApiException.class);

        // Signed in successfully, show authenticated UI.
        updateUI(account);
    } catch (ApiException e) {
        // The ApiException status code indicates the detailed failure reason.
        // Please refer to the GoogleSignInStatusCodes class reference for more information.
        Log.w(TAG, "signInResult:failed code=" + e.getStatusCode());
        updateUI(null);
    }
}

You can also get the user’s email address with getEmail, the user’s Google ID (for client-side use) with getId, and an ID token for the user with getIdToken. If you need to pass the currently signed-in user to a backend server, send the ID token to your backend server and validate the token on the server.

GIA SƯ TIẾNG ANH ⭐️⭐️⭐️⭐️⭐️

GIA SƯ TOÁN BẰNG TIẾNG ANH ⭐️⭐️⭐️⭐️⭐️

GIA SƯ DẠY SAT ⭐️⭐️⭐️⭐️⭐️

Mọi chi tiết liên hệ với chúng tôi :
TRUNG TÂM GIA SƯ TÂM TÀI ĐỨC
Các số điện thoại tư vấn cho Phụ Huynh :
Điện Thoại : 091 62 65 673 hoặc 01634 136 810
Các số điện thoại tư vấn cho Gia sư :
Điện thoại : 0902 968 024 hoặc 0908 290 601

Hãy bình luận đầu tiên

Để lại một phản hồi

Thư điện tử của bạn sẽ không được hiện thị công khai.


*