Android google plus login button not working

I am trying to embed a Google+ login in my work. I followed the google dev tutorial, but when I click the SignIn button, nothing happens. I think I made some mistakes, here is the code:

public class MainActivity extends FragmentActivity implements OnClickListener,
    ConnectionCallbacks, OnConnectionFailedListener {

public static final String mAPP_ID = "xxxx";
private static final int REQUEST_CODE_RESOLVE_ERR = 9000;
private static final String TAG = "MainActivity";

private ProgressDialog mConnectionProgressDialog;
private PlusClient mPlusClient;
private ConnectionResult mConnectionResult;

private ImageButton googleSignOutButton;

AssetsExtracter mTask;

private MainFragment mainFragment;

static {
    IMetaioSDKAndroid.loadNativeLibs();
}

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

    if (savedInstanceState == null) {
        // Add the fragment on initial activity setup
        mainFragment = new MainFragment();
        getSupportFragmentManager().beginTransaction()
                .add(android.R.id.content, mainFragment).commit();
    } else {
        // Or set the fragment from restored state info
        mainFragment = (MainFragment) getSupportFragmentManager()
                .findFragmentById(android.R.id.content);
    }

    mPlusClient = new PlusClient.Builder(this, this, this)
            .setActions("http://schemas.google.com/AddActivity")
            .setScopes(Scopes.PLUS_LOGIN) 
            .build();
    // Progress bar to be displayed if the connection failure is not
    // resolved.
    mConnectionProgressDialog = new ProgressDialog(this);
    mConnectionProgressDialog.setMessage("Signing in...");

    mTask = new AssetsExtracter();
    mTask.execute(0);

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

@Override
public void onConnectionFailed(ConnectionResult result) {
    if (mConnectionProgressDialog.isShowing()) {
        // The user clicked the sign-in button already. Start to resolve
        // connection errors. Wait until onConnected() to dismiss the
        // connection dialog.
        if (result.hasResolution()) {
            try {
                result.startResolutionForResult(this,
                        REQUEST_CODE_RESOLVE_ERR);
            } catch (SendIntentException e) {
                mPlusClient.connect();
            }
        }
    }

    // Save the intent so that we can start an activity when the user clicks
    // the sign-in button.
    mConnectionResult = result;

}

@Override
public void onConnected(Bundle connectionHint) {
    // We've resolved any connection errors.
    mConnectionProgressDialog.dismiss();
    Toast.makeText(this, "User is connected!", Toast.LENGTH_LONG).show();

}

@Override
public void onDisconnected() {
    Log.d(TAG, "disconnected");

}

@Override
protected void onActivityResult(int requestCode, int responseCode,
        Intent intent) {
    super.onActivityResult(requestCode, responseCode, intent);
    if (requestCode == REQUEST_CODE_RESOLVE_ERR
            && responseCode == RESULT_OK) {
        mConnectionResult = null;
        mPlusClient.connect();
    }
}

@Override
protected void onStart() {
    super.onStart();
    mPlusClient.connect();
}

@Override
protected void onStop() {
    super.onStop();
    mPlusClient.disconnect();
}

@Override
public void onClick(View v) {
    if (v.getId() == R.id.sign_in_button
            && !mPlusClient.isConnected()) {
        if (mConnectionResult == null) {
            mConnectionProgressDialog.show();
        } else {
            try {
                mConnectionResult.startResolutionForResult(
                        getParent(), REQUEST_CODE_RESOLVE_ERR);
            } catch (SendIntentException e) {
                // Try connecting again.
                mConnectionResult = null;
                mPlusClient.connect();
            }
        }
    }
}

}

EDIT : I found that in the onConncectionFailed () method, if I delete the first "if ()" that checks if the Dialog process is displayed when the application starts without clicking anything, a google + dialog appears asking me to log in. this is strange

EDIT : I resolved my problem using a regular Button and embedding onClick on it, following the guide of Google Dev

+4
2

, SHA-1 , APK APK , Android Studio.
SHA-1 , .

SHA-1 , / apk Android Studio:

Google Cloud Console > API-p > " ".
" OAuth2.0" " Android" SHA-1 ( , SHA-1: https://developer.android.com/studio/publish/app-signing.html)
Cloud Console , . SHA-1. app/... , , .

0

All Articles