Android 谷歌登录API对棒棒糖不起作用 谷歌登录无法在棒棒糖中获得响应

Android 谷歌登录API对棒棒糖不起作用 谷歌登录无法在棒棒糖中获得响应,android,google-login,Android,Google Login,嗨,我需要在我的应用程序中集成谷歌登录 我从中找到帮助并从中获取代码 我在4.1和4.4中进行了测试 它在所有版本中都可以正常工作,但在棒棒糖中不起作用 每当我运行在棒棒糖,然后它会显示进度对话框,然后也会得到谷歌的a/c,但然后无法得到任何响应 谷歌登录码 公共类的重要性扩展了AppCompatActivity实现 GoogleAppClient.OnConnectionFailedListener, View.OnClickListener{ 私有静态最终字符串标记=“符号活动”; 专用静态

嗨,我需要在我的应用程序中集成谷歌登录

我从中找到帮助并从中获取代码

我在4.1和4.4中进行了测试

它在所有版本中都可以正常工作,但在棒棒糖中不起作用

每当我运行在棒棒糖,然后它会显示进度对话框,然后也会得到谷歌的a/c,但然后无法得到任何响应

谷歌登录码
公共类的重要性扩展了AppCompatActivity实现
GoogleAppClient.OnConnectionFailedListener,
View.OnClickListener{
私有静态最终字符串标记=“符号活动”;
专用静态最终输入RC\U符号\U IN=9001;
私人GoogleapClient MGoogleapClient;
私有文本视图mStatusTextView;
private ProgressDialog mProgressDialog;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//观点
mStatusTextView=(TextView)findViewById(R.id.status);
//按钮侦听器
findviewbyd(R.id.sign_in_按钮);
findviewbyd(R.id.sign\u out\u按钮);
findviewbyd(R.id.disconnect_按钮);
//[开始配置\登录]
//配置登录以请求用户ID、电子邮件地址和基本信息
//配置文件。ID和基本配置文件包含在默认登录中。
GoogleSignenOptions gso=新建GoogleSignenOptions.Builder(GoogleSignenOptions.DEFAULT\u登录)
.requestEmail()
.build();
//[结束配置\登录]
//[启动构建客户端]
//通过访问Google登录API和
//gso指定的选项。
mgoogleapclient=新的Googleapclient.Builder(此)
.enableautomanager(此/*FragmentActivity*/,此/*OnConnectionFailedListener*/)
.addApi(Auth.GOOGLE\u SIGN\u IN\u API,gso)
.build();
//[最终构建客户机]
//[启动自定义按钮]
//自定义登录按钮。登录按钮可以在中显示
//多种尺寸和配色方案。也可以根据上下文进行调整
//基于请求的作用域呈现。例如,红色按钮可能会
//在请求Google+范围时显示,但显示一个白色按钮
//仅请求基本配置文件时可能会显示。请尝试添加
//Scopes.PLUS\u登录到GoogleSignations以查看
//差别。
SignInButton SignInButton=(SignInButton)findViewById(R.id.sign_in_按钮);
signInButton.setSize(signInButton.SIZE_标准);
设置范围(gso.getScopeArray());
//[结束自定义按钮]
}
@凌驾
public void onStart(){
super.onStart();
OptionalPendingreult opr=Auth.GoogleSignInApi.silentSignIn(MGoogleAppClient);
if(opr.isDone()){
//如果用户的缓存凭据有效,则OptionalPendingreult将“完成”
//谷歌搜索结果将立即发布。
Log.d(标记“已缓存登录”);
GoogleSignInResult结果=操作获取();
handleSignInResult(结果);
}否则{
//如果用户以前未在此设备上登录或登录已过期,
//此异步分支将尝试以静默方式登录用户。跨设备
//此分支中将发生单点登录。
showProgressDialog();
操作setResultCallback(新的ResultCallback(){
@凌驾
公开作废结果(GoogleSignInResult GoogleSignInResult){
hideProgressDialog();
handleSignInResult(谷歌SignInResult);
}
});
}
}
//[在ActivityResult上启动]
@凌驾
ActivityResult上的公共void(int请求代码、int结果代码、意图数据){
super.onActivityResult(请求代码、结果代码、数据);
//从GoogleSignInApi.getsigninent(…)启动Intent返回的结果;
if(requestCode==RC\u登录){
GoogleSignInResult结果=Auth.GoogleSignInApi.getSignInResultFromIntent(数据);
handleSignInResult(结果);
}
}
//[活动结束结果]
//[启动手柄点火结果]
私有无效handleSignInResult(Google SignInResult结果){
Log.d(标记为“handleSignInResult:+result.issucess());
if(result.issucess()){
//成功登录,显示已验证的UI。
GoogleSignInAccount acct=result.getSignInAccount();
mStatusTextView.setText(getString(R.string.signed_in_fmt,acct.getDisplayName());
更新(真);
}否则{
//已注销,显示未经验证的用户界面。
更新(假);
}
}
//[结束手柄点火结果]
//[开始签名]
私人无效签名(){
意向符号=Auth.googlesignianpi.getsignient(mgoogleapclient);
startActivityForResult(签名、注册);
}
//[结束签名]
//[开始注销]
私有无效签出(){
Auth.GoogleSignInApi.signOut(mgoogleapclient.setResultCallback)(
新的ResultCallback(){
@凌驾
公共void onResult(状态){
//[开始时不包括]
更新(假);
//[完]
}
});
}
//[结束签出]
//[开始撤销访问]
私有void revokeAccess(){
Auth.GoogleSignInApi.revokeAccess(mGoogleApiClient.setResultCallback)(
新的ResultCallback(){
@凌驾
公共void onResult(状态){
//[开始时不包括]
更新(假);
//[完]
}
});
}
//[结束撤销访问]
@凌驾
公共无效onConnectionFailed(ConnectionResult ConnectionResult){
//发生了无法解决的错误,Google API(包括登录)将无法解决
//有空。
Log.d(标记“onConnectionFailed:+connectionResult”);
}
私有void showProgressDialog(){
public class SignInActivity extends AppCompatActivity implements
    GoogleApiClient.OnConnectionFailedListener,
    View.OnClickListener {

private static final String TAG = "SignInActivity";
private static final int RC_SIGN_IN = 9001;

private GoogleApiClient mGoogleApiClient;
private TextView mStatusTextView;
private ProgressDialog mProgressDialog;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Views
    mStatusTextView = (TextView) findViewById(R.id.status);

    // Button listeners
    findViewById(R.id.sign_in_button).setOnClickListener(this);
    findViewById(R.id.sign_out_button).setOnClickListener(this);
    findViewById(R.id.disconnect_button).setOnClickListener(this);

    // [START configure_signin]
    // Configure sign-in to request the user's ID, email address, and basic
    // profile. ID and basic profile are included in DEFAULT_SIGN_IN.
    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
            .requestEmail()
            .build();
    // [END configure_signin]

    // [START build_client]
    // Build a GoogleApiClient with access to the Google Sign-In API and the
    // options specified by gso.
    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .build();
    // [END build_client]

    // [START customize_button]
    // Customize sign-in button. The sign-in button can be displayed in
    // multiple sizes and color schemes. It can also be contextually
    // rendered based on the requested scopes. For example. a red button may
    // be displayed when Google+ scopes are requested, but a white button
    // may be displayed when only basic profile is requested. Try adding the
    // Scopes.PLUS_LOGIN scope to the GoogleSignInOptions to see the
    // difference.
    SignInButton signInButton = (SignInButton) findViewById(R.id.sign_in_button);
    signInButton.setSize(SignInButton.SIZE_STANDARD);
    signInButton.setScopes(gso.getScopeArray());
    // [END customize_button]
}

@Override
public void onStart() {
    super.onStart();

    OptionalPendingResult<GoogleSignInResult> opr = Auth.GoogleSignInApi.silentSignIn(mGoogleApiClient);
    if (opr.isDone()) {
        // If the user's cached credentials are valid, the OptionalPendingResult will be "done"
        // and the GoogleSignInResult will be available instantly.
        Log.d(TAG, "Got cached sign-in");
        GoogleSignInResult result = opr.get();
        handleSignInResult(result);
    } else {
        // If the user has not previously signed in on this device or the sign-in has expired,
        // this asynchronous branch will attempt to sign in the user silently.  Cross-device
        // single sign-on will occur in this branch.
        showProgressDialog();
        opr.setResultCallback(new ResultCallback<GoogleSignInResult>() {
            @Override
            public void onResult(GoogleSignInResult googleSignInResult) {
                hideProgressDialog();
                handleSignInResult(googleSignInResult);
            }
        });
    }
}

// [START onActivityResult]
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
    if (requestCode == RC_SIGN_IN) {
        GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data);
        handleSignInResult(result);
    }
}
// [END onActivityResult]

// [START handleSignInResult]
private void handleSignInResult(GoogleSignInResult result) {
    Log.d(TAG, "handleSignInResult:" + result.isSuccess());
    if (result.isSuccess()) {
        // Signed in successfully, show authenticated UI.
        GoogleSignInAccount acct = result.getSignInAccount();
        mStatusTextView.setText(getString(R.string.signed_in_fmt, acct.getDisplayName()));
        updateUI(true);
    } else {
        // Signed out, show unauthenticated UI.
        updateUI(false);
    }
}
// [END handleSignInResult]

// [START signIn]
private void signIn() {
    Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient);
    startActivityForResult(signInIntent, RC_SIGN_IN);
}
// [END signIn]

// [START signOut]
private void signOut() {
    Auth.GoogleSignInApi.signOut(mGoogleApiClient).setResultCallback(
            new ResultCallback<Status>() {
                @Override
                public void onResult(Status status) {
                    // [START_EXCLUDE]
                    updateUI(false);
                    // [END_EXCLUDE]
                }
            });
}
// [END signOut]

// [START revokeAccess]
private void revokeAccess() {
    Auth.GoogleSignInApi.revokeAccess(mGoogleApiClient).setResultCallback(
            new ResultCallback<Status>() {
                @Override
                public void onResult(Status status) {
                    // [START_EXCLUDE]
                    updateUI(false);
                    // [END_EXCLUDE]
                }
            });
}
// [END revokeAccess]

@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
    // An unresolvable error has occurred and Google APIs (including Sign-In) will not
    // be available.
    Log.d(TAG, "onConnectionFailed:" + connectionResult);
}

private void showProgressDialog() {
    if (mProgressDialog == null) {
        mProgressDialog = new ProgressDialog(this);
        mProgressDialog.setMessage(getString(R.string.loading));
        mProgressDialog.setIndeterminate(true);
    }

    mProgressDialog.show();
}

private void hideProgressDialog() {
    if (mProgressDialog != null && mProgressDialog.isShowing()) {
        mProgressDialog.hide();
    }
}

private void updateUI(boolean signedIn) {
    if (signedIn) {
        findViewById(R.id.sign_in_button).setVisibility(View.GONE);
        findViewById(R.id.sign_out_and_disconnect).setVisibility(View.VISIBLE);
    } else {
        mStatusTextView.setText(R.string.signed_out);

        findViewById(R.id.sign_in_button).setVisibility(View.VISIBLE);
        findViewById(R.id.sign_out_and_disconnect).setVisibility(View.GONE);
    }
}

@Override
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.sign_in_button:
            signIn();
            break;
        case R.id.sign_out_button:
            signOut();
            break;
        case R.id.disconnect_button:
            revokeAccess();
            break;
      }
   }
}