Google+登录按钮无法使用Android

时间:2014-12-04 20:41:16

标签: android authentication google-plus

我正在尝试为我的Android应用实施Google+身份验证,但登录按钮不起作用。

我在SignInActivity中的onClick方法。我也用普通按钮测试了它。

public void onClick(View view) {
if (view.getId() == R.id.sign_in_button){
        Toast.makeText(this, "Log in pressed", Toast.LENGTH_SHORT).show();
    }
if (view.getId() == R.id.button1) {
        Toast.makeText(this, "Log in pressed", Toast.LENGTH_SHORT).show();
        mGoogleApiClient.connect();
        }
}

显示按钮属性的XML。

 <com.google.android.gms.common.SignInButton
    android:id="@+id/sign_in_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:onClick="onClick" />

 <Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/sign_in_button"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="49dp"
    android:onClick="onClick"
    android:text="Button" />

当我按下正常按钮时,吐司显得很好并且身份验证有效,但是当我按下g +按钮时没有任何反复发生..

2 个答案:

答案 0 :(得分:1)

似乎你需要将onClickListener提供给你的SignIn Button。像这样的东西

public class YourActivity extends Activity implements View.OnClickListener{
   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.yourlayout);

      //You probably miss this line:
      this.findViewById(R.id.sign_in_button).setOnClickListener(this);

      this.findViewById(R.id.button1).setOnClickListener(this);
   }

   public void onClick(View view) {
     // Your stuff...
   }
}

答案 1 :(得分:0)

这应该有效:

转到the Google Developer Console并启用 Google+ API