PlusOneButton on Android, how do I know if the user has clicked?

In my Android app, I give the option to click the Google +1 button.

This works great with the following code from the developer source material ( https://developers.google.com/+/mobile/android/recommend ):

mPlusClient = new PlusClient.Builder(this, this, this)
    .clearScopes()
    .build();  

mPlusOneButton = (PlusOneButton) findViewById(R.id.plus_one_button);

      

Now I would like to detect when the user clicks that button, so I tried this:

mPlusOneButton.setOnClickListener(new OnClickListener() {
    public void onClick(View v) {                   
        Toast.makeText(this, "Thanks for your +1", Toast.LENGTH_LONG).show();
    }
});

      

But it doesn't do anything, it doesn't display the toast message.

Alternatively, I was thinking that the player double-clicked the button: first, it's a regular Button object that would make the plus button one visible, and the second one would be the plus button. but this is an awkward user interface

How can I detect that the user has clicked this button?

+2


source to share


3 answers


Plus one button provides a listener function to detect a button press. Here is the code.



    mPlusOneButton.setOnPlusOneClickListener(new PlusOneButton.OnPlusOneClickListener() {
        @Override
        public void onPlusOneClick(Intent intent) {
            Log.w(tag,"plus one click");

        }
    });

      

+1


source


Don't use setOnPlusOneClickListener (or any listener) with SDK 13 (and possibly in future versions), it throws an error (infinite rotation of the progress bar on the +1 button when you click on it).



+3


source


Use ActivityForResult to select a user.

mPlusOneButton.setOnPlusOneClickListener(new PlusOneButton.OnPlusOneClickListener() {
                @Override
                public void onPlusOneClick(Intent intent) {
                    startActivityForResult(intent, 0);
                }
            });

      

Check result code

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == -1) {
      // OK or SHARE

    } else {
      //UNDO

    }

}

      

+2


source







All Articles