How to hardcode a Google Account in Android?

129 Views Asked by At

So, I was using the Google Drive API in one of my applications and when the application starts it asks for Google Sign in and I have to sign in using the Google Account on which Drive API is enabled. So then I can upload any file using my app to the drive. But I wondered if I could sign in to that particular Google Account through the code itself, by putting the credentials inside the code. So when I open the application it should automatically sign in to that Account which has Drive API enabled and then the Application can be used to upload any files to that particular drive.

Is this possible?

1

There are 1 best solutions below

0
Tartar On

You actually do not need to hard code. First, you may check if you have an already signed in user by using this line of code:

GoogleSignInAccount account = GoogleSignIn.getLastSignedInAccount(this);

If you already have one you pass the info of this user without even needing to sign in again. Or, there is another way called silent sign-in.

GoogleSignIn.silentSignIn()

With a silent sign in you won't be asked for credentials every time, once you sign in successfully. More info can be found here.