[英]google+ android app does not log me out and misconfigured in login flow
我是android应用程序的新手,并且正在与android应用程序进行google +集成,但是我在从google帐户注销时面临问题。我看过很多教程,也下载了许多演示项目,但都徒劳无功。 而且登录流程不符合要求。 下面,我将向您解释单击登录按钮后应用程序执行的步骤。 抱歉,我无法发布我的应用程序屏幕的快照。
下面是我的代码:
MainActivity.java
package com.gem.google;
import java.util.Arrays;
import java.util.List;
import android.content.Intent;
import android.content.IntentSender.SendIntentException;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import com.gem.google.R;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks;
import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener;
import com.google.android.gms.common.SignInButton;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.plus.Plus;
public class MainActivity extends FragmentActivity implements
ConnectionCallbacks , OnConnectionFailedListener
{
/* Request code used to invoke sign in user interactions. */
private static final int RC_SIGN_IN = 0;
private boolean mSignInClicked;
/* Store the connection result from onConnectionFailed callbacks so that we can
* resolve them when the user clicks sign-in.
*/
private ConnectionResult mConnectionResult;
/* Client used to interact with Google APIs. */
private GoogleApiClient mGoogleApiClient;
private boolean mIntentInProgress;
private SignInButton signinbt;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mGoogleApiClient = build_GoogleApiClient();
setContentView(R.layout.activity_main);
signinbt=(SignInButton) findViewById(R.id.sign_in_button);
signinbt.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
if (view.getId() == R.id.sign_in_button
&& !mGoogleApiClient.isConnecting()) {
mSignInClicked = true;
resolveSignInError();
}
}});
}
private GoogleApiClient build_GoogleApiClient() {
// When we build the GoogleApiClient we specify where connected and
// connection failed callbacks should be returned, which Google APIs our
// app uses and which OAuth 2.0 scopes our app requests.
return new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API)
.addScope(Plus.SCOPE_PLUS_LOGIN)
.build();
}
protected void onStart() {
super.onStart();
mGoogleApiClient.connect();
}
protected void onStop() {
super.onStop();
if (mGoogleApiClient.isConnected()) {
mGoogleApiClient.disconnect();
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == RC_SIGN_IN) {
if (resultCode != RESULT_OK) {
mSignInClicked = false;
}
mIntentInProgress = false;
if (!mGoogleApiClient.isConnecting()) {
mGoogleApiClient.connect();
}
}
}
private 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();
}
}
}
public void onConnectionFailed(ConnectionResult result) {
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();
}
}
}
public void onConnected(Bundle connectionHint) {
mSignInClicked = false;
Intent i = new Intent(MainActivity.this,nextscreen.class);
startActivity(i);
}
public void onConnectionSuspended(int cause) {
mGoogleApiClient.connect();
}
public void onDisconnected() {
// TODO Auto-generated method stub
}
}
nextscren.java
import android.widget.Button;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.plus.Plus;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
//import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
//import android.widget.Button;
public class nextscreen extends Activity implements
GoogleApiClient.ConnectionCallbacks {
private Button signoutbt;
private GoogleApiClient mGoogleApiClient;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
// .addOnConnectionFailedListener(this)
.addApi(Plus.API)
.addScope(Plus.SCOPE_PLUS_LOGIN)
.build();
setContentView(R.layout.screen_next);
signoutbt=(Button) findViewById(R.id.btn_sign_out);
signoutbt.setVisibility (View.GONE);
if(mGoogleApiClient.isConnected())
{
signoutbt.setVisibility (View.VISIBLE);
signoutbt.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
if (view.getId() == R.id.btn_sign_out) {
if (mGoogleApiClient.isConnected()) {
Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
mGoogleApiClient.disconnect();
mGoogleApiClient.connect();
// CookieSyncManager.createInstance(mGoogleApiClient);
// CookieManager cookieManager = CookieManager.getInstance();
// cookieManager.removeAllCookie();
//CookieSyncManager.getInstance().sync() ;
signoutbt.setVisibility (View.GONE);
Intent i = new Intent(nextscreen.this,MainActivity.class);
startActivity(i);
// Toast.makeText(this, "User is logout!", Toast.LENGTH_LONG).show();
}
}
}
});
}
}
public void onConnected(Bundle connectionHint) {
}
public void onConnectionSuspended(int cause) {
mGoogleApiClient.connect();
}
}
nextscreen活动是一类,其中控件在登录后继续连接,我在其中编写注销按钮的代码。
所以我想要的是:
上面的第7步不应存在,即在未出现同意屏幕登录屏幕之前。
所以请大家帮我,告诉我我哪里错了。 对于这个漫长的问题感到抱歉,但我很无助,别无选择。 请理解并提出建议。
经过长时间的研究,终于解决了这个问题。 轰鸣声是注销的方法
private void signOutFromGplus() {
if (mGoogleApiClient.isConnected()) {
Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
mGoogleApiClient.disconnect();
}
}
之后,在片段或活动的onPause处,调用signOutFromGplus,因为我需要的所有详细信息都已经在我的SharedPreference上,我通过我的应用程序使用了所有细节。
@Override
public void onPause() {
super.onPause();
signOutFromGplus();
}
因此,回到片段上,它已经是SignedOut。 所以它不会自动登录了。
希望这会有所帮助.``
问候
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.