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) {
mainFragment = new MainFragment();
getSupportFragmentManager().beginTransaction()
.add(android.R.id.content, mainFragment).commit();
} else {
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();
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()) {
if (result.hasResolution()) {
try {
result.startResolutionForResult(this,
REQUEST_CODE_RESOLVE_ERR);
} catch (SendIntentException e) {
mPlusClient.connect();
}
}
}
mConnectionResult = result;
}
@Override
public void onConnected(Bundle connectionHint) {
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) {
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