gpt4 book ai didi

android - Android 上的 Google+ 登录按钮在点击时没有任何反应

转载 作者:太空狗 更新时间:2023-10-29 15:01:48 25 4
gpt4 key购买 nike

我正在尝试在我的 Android 应用程序中实现 Google+ 登录。我遵循了 Google+ API 教程。但是,当我单击登录按钮时,没有任何反应,没有出现登录对话框或提示。 Logcat 也没有显示任何错误。当我遵循 Google+ API 文档时,我似乎无法理解为什么这不起作用。

这是我的代码:

package com.chromiumapps.fost;

import android.content.Intent;
import android.content.IntentSender.SendIntentException;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
import static android.view.View.*;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesClient.ConnectionCallbacks;
import com.google.android.gms.common.GooglePlayServicesClient.OnConnectionFailedListener;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.plus.Plus;

public class FostActivity extends FragmentActivity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, OnClickListener {

/* Called when the activity is first created. */

/*
* public boolean Facebook = false; public boolean Twitter = false; public
* boolean Googleplus = false; public boolean Blogger = false;
*/

private MainFragment mainFragment;
SharedPreferences pref;




private static final int RC_SIGN_IN=0;
private GoogleApiClient mGoogleApiClient;
private boolean mIntentInProgress;
private boolean mSignInClicked;

private ConnectionResult mConnectionResult;




@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
pref = getPreferences(0);
SharedPreferences.Editor edit = pref.edit();
edit.putString("CONSUMER_KEY", CONSUMER_KEY);
edit.putString("CONSUMER_SECRET", CONSUMER_SECRET);
edit.commit();

if (savedInstanceState == null) {
// Add the fragment on initial activity setup
mainFragment = new MainFragment();
getSupportFragmentManager().beginTransaction()
.add(android.R.id.content, mainFragment).commit();
//s = new ShareBarActivity();
//getSupportFragmentManager().beginTransaction()
//.add(android.R.id.content, s).commit();


} else {
// Or set the fragment from restored state info
mainFragment = (MainFragment) getSupportFragmentManager().findFragmentById(android.R.id.content);
//linkedInFragment = (LinkedIn_Fragment) getSupportFragmentManager().findFragmentById(android.R.id.content);

}
setContentView(R.layout.main);


findViewById(R.id.sign_in_button).setOnClickListener(this);
findViewById(R.id.sign_out_button).setOnClickListener(this);
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API, new Plus.PlusOptions.Builder().build())
.addScope(Plus.SCOPE_PLUS_LOGIN)
.build();


}

protected void onStart(){
super.onStart();
mGoogleApiClient.connect();
}

protected void onStop(){
super.onStop();
if (mGoogleApiClient.isConnected()){
mGoogleApiClient.disconnect();

}

}
protected void onAcitivityResult(int requestCode, int ResponseCode, Intent intent){
if (requestCode==RC_SIGN_IN){
if (ResponseCode != RESULT_OK) {
mSignInClicked = false;
}

mIntentInProgress = false;

if (!mGoogleApiClient.isConnecting()) {
mGoogleApiClient.connect();
}
}
}



@Override
public void onConnected(Bundle arg0) {
// TODO Auto-generated method stub
mSignInClicked = false;

}

@Override
public void onConnectionSuspended(int arg0) {
// TODO Auto-generated method stub
mGoogleApiClient.connect();
}



public void onConnectionFailed(ConnectionResult result) {
// TODO Auto-generated method stub
if (!mIntentInProgress) {
// Store the ConnectionResult so that we can use it later when the user clicks
// 'sign-in'.
mConnectionResult = result;

if (mSignInClicked) {
// The user has already clicked 'sign-in' so we attempt to resolve all
// errors until the user is signed in, or they cancel.
resolveSignInError();
}
}

}

protected void resolveSignInError(){
if(mConnectionResult.hasResolution()){
try {
mIntentInProgress = true;
startIntentSenderForResult(mConnectionResult.getResolution().getIntentSender(),
RC_SIGN_IN, null, 0, 0, 0);
} catch (SendIntentException e) {
// The intent was canceled before it was sent. Return to the default
// state and attempt to connect to get an updated ConnectionResult.
mIntentInProgress = false;
mGoogleApiClient.connect();
}
}

}

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(v.getId()==R.id.sign_in_button && !mGoogleApiClient.isConnecting()){
mSignInClicked=true;

resolveSignInError();

}

if(v.getId()==R.id.sign_out_button){
if(mGoogleApiClient.isConnected()){
Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
mGoogleApiClient.disconnect();
mGoogleApiClient.connect();
}
}


}
}

最佳答案

在 mGoogleApiClient 试试这个

   mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApiIfAvailable(Drive.API)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this).addApi(Plus.API, Plus.PlusOptions.builder().build())
.addScope(Plus.SCOPE_PLUS_LOGIN).build();

关于android - Android 上的 Google+ 登录按钮在点击时没有任何反应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25754889/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com