【发布时间】:2012-01-12 22:51:59
【问题描述】:
我只是想知道是否可以在我的 Android 应用程序中添加一个 Google +1 按钮。 我在 Android Market 上看到了 +1,所以我认为会有一些方法可以做到这一点。
【问题讨论】:
-
大家好,我已经为 +1 按钮生成了客户端 ID,但不知道在代码中的何处使用。有什么想法吗?
标签: android google-plus google-plus-one
我只是想知道是否可以在我的 Android 应用程序中添加一个 Google +1 按钮。 我在 Android Market 上看到了 +1,所以我认为会有一些方法可以做到这一点。
【问题讨论】:
标签: android google-plus google-plus-one
借助适用于 Android 的 Google+ 平台,您现在可以在自己的 Android 应用中集成原生 +1 按钮。
1) 您首先需要在 Activity 中 initialize 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" />
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);
}
4) 每次 Activity 在 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);
}
更多信息请见https://developers.google.com/+/mobile/android/#recommend_content_with_the_1_button
【讨论】:
接受的答案已过时....
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" />
活动:
// 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);
}
甚至在此之前,这个链接:
https://developers.google.com/+/mobile/android/getting-started
【讨论】:
要添加 google plus one,首先您需要在开发者控制台中启用 API,然后使用包名称注册您的应用,然后将其包含在您的应用中。
这里是完整的例子和详细的解释。
【讨论】: