Android Google Plus SDK: how to get callback on the +1 button (PlusOneButton)
Asked Answered
F

1

6

I added a +1 button in my Android app. I would like to add a callback in order to know what happened after the user clicked on the +1 button (did he validate its +1 ?, did he abort ? ...)

How can I do that ?

Thanks !

Festschrift answered 6/11, 2013 at 9:13 Comment(0)
H
0

You can add a listener to check when the button is clicked and later check the result of the activity.

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;
        }
    }
}

Sources: Handling the click Getting a result from an activity

I hope that this is what your were asking, and more importantly that this was helpful.

Hugues answered 25/7, 2014 at 3:23 Comment(2)
What do you call the "activity to display the +1 confirmation dialog" ? What does this confirmation dialog look like ? Is it the dialog with the sign in / sign out / revoke buttons ? Or the Google Plus dialog to post something on the user G+ wall ? Thanks.Festschrift
This confirmation dialog verifies that the user is signed in. The +1 button does not display a confirmation alert because it can be undone by reclicking the button.Hugues

© 2022 - 2024 — McMap. All rights reserved.