Je rencontre un problème pour comprendre comment PlusClient.Builder.clearScope().build() diffère de PlusClient.Builder.setScope().build() . Dans le premier cas, mon bouton "plus un" fonctionne correctement, mais dans le second cas, le bouton est grisé sans qu'aucun compte G+ n'apparaisse.
Pourquoi appeler setScope() provoquer ce problème ?
import android.app.ProgressDialog;
import android.content.Intent;
import android.content.IntentSender.SendIntentException;
import android.content.res.Resources;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
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.Scopes;
import com.google.android.gms.plus.PlusClient;
import com.google.android.gms.plus.PlusOneButton;
public class SignInActivity extends ActionBarActivity
implements View.OnClickListener, ConnectionCallbacks, OnConnectionFailedListener
{
private final String TAG = SignInActivity.class.getSimpleName();
private final int REQUEST_CODE_RESOLVE_ERR = 9000;
private final int PLUS_ONE_REQUEST_CODE = 1;
private PlusOneButton mPlusOneBtn;
private ProgressDialog mConnectionProgressDialog;
private PlusClient mPlusClient;
private Resources mRes; private String mURL;
private ConnectionResult mConnectionResult;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.sign_in_activity);
mRes = getResources();
mURL = mRes.getString(R.string.share_url);
findViewById(R.id.sign_in_button_dude).setOnClickListener(this);
mPlusOneBtn = (PlusOneButton) findViewById(R.id.plus_one_standard_button);
mPlusClient = new PlusClient.Builder(this, this, this).clearScopes().build();
mConnectionProgressDialog = new ProgressDialog(this);
mConnectionProgressDialog.setMessage("Signing in...");
}
@Override
protected void onStart() {
super.onStart();
mPlusClient.connect();
}
@Override
protected void onStop() {
super.onStop();
mPlusClient.disconnect();
}
@Override
protected void onResume() {
super.onResume();
mPlusOneBtn.initialize(mPlusClient, mURL, PLUS_ONE_REQUEST_CODE);
}
}
Mais maintenant, lorsque j'utilise .setScopes(), le bouton standard plus un est grisé.
mPlusClient = new PlusClient.Builder(this, this, this).
.setScopes(Scopes.APP_STATE).setScopes(Scopes.GAMES)
.setScopes(Scopes.PLUS_LOGIN).setScopes(Scopes.PLUS_PROFILE)
.build();
res/layout/sign_in_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:id="@+id/sign_row"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp" >
<com.google.android.gms.common.SignInButton
android:id="@+id/sign_in_button_dude"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<Button
android:id="@+id/sign_out_button"
style="@android:style/TextAppearance.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/sign_in_button_dude"
android:text="@string/sign_out_button_name"
android:textColor="@color/black" />
<Button
android:id="@+id/revoke_access_button"
style="@android:style/TextAppearance.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/sign_out_button"
android:text="@string/revoke_access_button_name"
android:textColor="@color/black" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/sign_row"
android:layout_marginBottom="8dp" >
<com.google.android.gms.plus.PlusOneButton
xmlns:plus="http://schemas.android.com/apk/lib/com.google.android.gms.plus"
android:id="@+id/plus_one_standard_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
plus:size="standard" />
<TextView
android:id="@+id/sign_in_status"
android:layout_below="@+id/plus_one_standard_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Default status" />
</RelativeLayout>
</RelativeLayout>