【发布时间】:2013-11-17 10:41:42
【问题描述】:
我在我的 Android 应用中添加了一个 +1 按钮。我想添加一个回调,以了解用户单击 +1 按钮后发生的情况(他是否验证了 +1 ?,他是否中止了?...)
我该怎么做?
谢谢!
【问题讨论】:
标签: android api google-plus google-play-services google-plus-one
我在我的 Android 应用中添加了一个 +1 按钮。我想添加一个回调,以了解用户单击 +1 按钮后发生的情况(他是否验证了 +1 ?,他是否中止了?...)
我该怎么做?
谢谢!
【问题讨论】:
标签: android api google-plus google-play-services google-plus-one
您可以添加一个侦听器来检查按钮何时被单击,然后检查活动的结果。
static final int PLUS_ONE_REQUEST = 1;
...
mPlusOneButton.setOnPlusOneClickListener(new PlusOneButton.OnPlusOneClickListener() {
@Override
public void onPlusOneClick(Intent intent) {
//here you can handle the initial click
//Start the activity to display the +1 confirmation dialog.
startActivityForResult(intent, PLUS_ONE_REQUEST);
}
});
...
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == PLUS_ONE_REQUEST) {
switch(resultCode) {
case RESULT_OK:
//here the operation was successful
break;
case RESULT_CANCELED:
//here the user backed out or failed
break;
}
}
}
来源: Handling the click Getting a result from an activity
我希望这是您的要求,更重要的是,这对您有所帮助。
【讨论】: