I’m developing an application on Android and I want to allow users to log in with their Google account. How can I achieve this?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
First insert the below line in your build.gradle dependencies
Now we need SHA-1 fingerprint which we have to give in Google Developers Console.
Java keytool is used to generate SHA-1 fingerprint. Open your command prompt [Open C:\Program Files\Java\jdk\bin then press Shift+Right Click] and execute the following command to generate SHA-1 fingerprint and for password enter android if prompted.
To authenticate and communicate with the Google+ APIs, you must create a Google Developers Console project where you have to enable the Google+ API and create an OAuth 2.0 Client ID.
Now it’s time to declare permissions to your mainfest file. This is how your manifest file will look like after adding meta-data and all the permissions.
Now we are heading towards our MainActivity.java class where we are going to do all our stuff for Google+ Login.
Create activity_main.xml which will contain our login and logout layout .
Thats it folks. You are done with Google+ Login. For more details you can visit here.
You can't exactly log in to an Android application using a Google account. You use a Google account to login to a website or webservice such as GMail, Calendar, etc., or a third party website if using OpenID. Since your app is not an website, this won't work. You can do either one of:
AccountManager
) on their phone, and only let them use the app if they have one. If an account is registered, you can be reasonably sure that they know the password (or they stole someone's phone...)You might want to authenticate the user using one of the google account already configured in your device like some of the apps do, for that follow the below link -
"Authenticating to OAuth2 Services" - http://developer.android.com/training/id-auth/authenticate.html
Download Sample from Google - Android SDK Manager/Extras/Google Play Services
In simple steps it does
This is another link which is good in explaining the process - http://android-developers.blogspot.in/2013/01/verifying-back-end-calls-from-android.html
you can follow below steps for Login in your app
Below is response format of above "userinfo" call
If you want Email id along with that response you have to modify
SCOPE = "oauth2:https://www.googleapis.com/auth/userinfo.profile";
to
SCOPE = "oauth2:https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email";
in that sample
Here is how I integrate google login with latest and smoothest way.
From this reference : google login android studio
first create app in google developer console and download configuration file and copy in app folder.
then add following in
build.gradle(Project: project_name)
add code in
build.gradle(Module:app)
add following in activity_main.xml
add below in MainActivity.java
Sure you might want to start with this:
https://developers.google.com/accounts/docs/OpenID
Come back when you get stuck!