Today I’m talking about integration Google’s +1 button with Android application.

This let’s improve rating of your application in Play Store.

Firstly need to add library or add a dependency to gradle file.
[xml]
dependencies {
compile ‘com.google.android.gms:play-services:7.3.0’
}
[/xml]

After it need to add +1 Button to your layout. Size of PlusOneButton may be standard, tall, small or medium. For changing size of button need to change size attribute.
size of +1 button

[xml]

[/xml]
Next step is updating an activity.
[java]
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.plus.Plus;
import com.google.android.gms.plus.PlusOneButton;

public class MainActivity extends AppCompatActivity {
private static final int PLUS_ONE_REQUEST_CODE = 0;
private static final String APP_URL = “https://play.google.com/store/apps/details?id=app_package”;
private PlusOneButton mPlusOneButton;
private GoogleApiClient mGoogleApiClient;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_plus_one);

mPlusOneButton = (PlusOneButton) findViewById(R.id.plus_one_button);
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Plus.API)
.addScope(Plus.SCOPE_PLUS_LOGIN)
.useDefaultAccount()
.build();
}

@Override
protected void onResume() {
super.onResume();
mPlusOneButton.initialize(APP_URL, PLUS_ONE_REQUEST_CODE);
}

@Override
protected void onStart() {
super.onStart();
mGoogleApiClient.connect();
}

@Override
protected void onStop() {
super.onStop();
mGoogleApiClient.disconnect();
}
}
[/java]
You must change app_package to your application package.
+1 button application demo

0 CommentsClose Comments

Leave a comment

Newsletter Subscribe

Get the Latest Posts & Articles in Your Email

We Promise Not to Send Spam:)