在Android应用中添加Google +1按钮

Emi*_*yan 30 android google-plus-one google-plus

我只是想知道是否还有在我的Android应用程序中添加Google +1按钮.我在Android Market上看过+1,所以我认为会有一些方法可以做到这一点.

Chi*_*hah 23

借助适用于Android的Google+平台,您现在可以在Android应用中集成原生+1按钮.

1)首先,您需要初始化PlusClient对象在你的活动.

2)在布局中包含PlusOneButton:

    <com.google.android.gms.plus.PlusOneButton
        xmlns:plus="http://schemas.android.com/apk/lib/com.google.android.gms.plus"
        android:id="@+id/plus_one_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        plus:size="standard"
        plus:annotation="inline" />
Run Code Online (Sandbox Code Playgroud)

3)将PlusOneButton分配给Activity.onCreate处理程序中的成员变量.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mPlusClient = new PlusClient(this, this, this);
    mPlusOneButton = (PlusOneButton) findViewById(R.id.plus_one_button);
}
Run Code Online (Sandbox Code Playgroud)

4)每次活动在Activity.onResume处理程序中获得焦点时,刷新PlusOneButton的状态.

protected void onResume() {
    super.onResume();
    // Refresh the state of the +1 button each time the activity receives focus.
    mPlusOneButton.initialize(mPlusClient, URL);
}
Run Code Online (Sandbox Code Playgroud)

有关详细信息,请参阅https://developers.google.com/+/mobile/android/#recommend_content_with_the_1_button

  • 什么是URL变量? (4认同)
  • 不再支持PlusClient构造函数,您应该使用PlusClient.Builder $ build (3认同)
  • 这个答案已经过时了.不再需要mPlusClient,反正mPlusOneButton.initialize()不会接受它.看看[这里](https://developers.google.com/+/mobile/android/recommend)的新方法 (3认同)
  • 您应该根据上次更新删除Scopes.PLUS_PROFILE (2认同)
  • 就我而言,我将链接发布到了Play商店:https://play.google.com/store/apps/details?id = com.package.app (2认同)

Jes*_*rix 10

接受的答案已经过时了......

XML:

<com.google.android.gms.plus.PlusOneButton
  xmlns:plus="http://schemas.android.com/apk/lib/com.google.android.gms.plus"
  android:id="@+id/plus_one_button"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  plus:size="standard"
  plus:annotation="inline" />
Run Code Online (Sandbox Code Playgroud)

活动:

// The request code must be 0 or greater.

    private static final int PLUS_ONE_REQUEST_CODE = 0;

protected void onResume() {
    super.onResume();
    // Refresh the state of the +1 button each time the activity receives focus.
    mPlusOneButton.initialize(URL, PLUS_ONE_REQUEST_CODE);
}
Run Code Online (Sandbox Code Playgroud)

甚至在那之前休闲这个链接:

https://developers.google.com/+/mobile/android/getting-started