HackerNam
Lurker
Step 1: Install Google Play Services
Step 2: Google Plus Intergration
https://developers.google.com/identity/sign-in/android/start-integrating#add-config
Step 3: Add file build.gradle
Step 4: Add file file manifest.xml
Step 5: Create Google Api Client to use Google+ API
Step 6: Sign into your Google account +
Step 7: Get user information
Step 8: Display user information
Full source code:
https://drive.google.com/file/d/0B7V9D29Tek7yU2I4dTc5b2FseVk/view?usp=sharinghttps://drive.google.com/file/d/0B7V9D29Tek7yU2I4dTc5b2FseVk/view?usp=sharing
Step 2: Google Plus Intergration
https://developers.google.com/identity/sign-in/android/start-integrating#add-config
Step 3: Add file build.gradle
Code:
apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'
...
dependencies {
compile 'com.google.android.gms:play-services:8.3.0'
}
Step 4: Add file file manifest.xml
JavaScript:
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
Step 5: Create Google Api Client to use Google+ API
Java:
private void buidNewGoogleApiClient()
{
google_api_client = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API,Plus.PlusOptions.builder().build())
.addScope(Plus.SCOPE_PLUS_LOGIN)
.build();
}
Step 6: Sign into your Google account +
Java:
private void gPlusSignIn() {
if (!google_api_client.isConnecting()) {
Log.d("user connected","connected");
is_signInBtn_clicked = true;
progress_dialog.show();
resolveSignInError();
}
}
Step 7: Get user information
Java:
public void onConnected(Bundle arg0) {
is_signInBtn_clicked = false;
getProfileInfo();
changeUI(true);
}
private void getProfileInfo() {
try {
if (Plus.PeopleApi.getCurrentPerson(google_api_client) != null) {
Person currentPerson = Plus.PeopleApi.getCurrentPerson(google_api_client);
setPersonalInfo(currentPerson);
} else {
Toast.makeText(getApplicationContext(),
"No Personal info mention", Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
e.printStackTrace();
}
}
Step 8: Display user information
Java:
private void setPersonalInfo(Person currentPerson)
{
String personName = currentPerson.getDisplayName();
String personPhotoUrl = currentPerson.getImage().getUrl();
String email = Plus.AccountApi.getAccountName(google_api_client);
TextView user_name = (TextView) findViewById(R.id.userName);
user_name.setText("Name: "+personName);
TextView gemail_id = (TextView)findViewById(R.id.emailId);
gemail_id.setText("Email Id: " +email);
setProfilePic(personPhotoUrl);
progress_dialog.dismiss();
Toast.makeText(this, "Person information is shown!", Toast.LENGTH_LONG).show();
}
Full source code:
https://drive.google.com/file/d/0B7V9D29Tek7yU2I4dTc5b2FseVk/view?usp=sharinghttps://drive.google.com/file/d/0B7V9D29Tek7yU2I4dTc5b2FseVk/view?usp=sharing