【问题标题】:GoogleApiClient wont even ask for a singupGoogleApiClient 甚至不会要求 singup
【发布时间】:2016-06-03 21:05:37
【问题描述】:

我正在尝试创建游戏。 我想实现你必须在开始时注册。 即使我调用 mGoogleApiClient.connect() 方法,我也不会收到登录请求: 这是代码。

MediaPlayer song1;
MediaPlayer buttonSound;


int brainEfficiency = 0;

//sound
boolean muted = true;

// int length;

Button BtnSound;
Button BtnGoogleLogin;

//SIGN IN
private static int RC_SIGN_IN = 9001;

private boolean mResolvingConnectionFailure = false;
private boolean mAutoStartSignInflow = true;
private boolean mSignInClicked = false;

boolean mExplicitSignOut = false;
boolean mInSignInFlow = false;

GoogleApiClient mGoogleApiClient;

//ON CREATION
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_title_screen);

    //Hide actionbar
    getSupportActionBar().hide();

    //Setting Flags
    getWindow().getDecorView().setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_IMMERSIVE
                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                    | View.SYSTEM_UI_FLAG_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
    );



    //Music
    song1 = MediaPlayer.create(this, R.raw.menu_loop);
    song1.setLooping(true);
    song1.setVolume(-15, -15);

    song1.start();

    buttonSound = MediaPlayer.create(this, R.raw.select);

    BtnSound = (Button) findViewById(R.id.BtnSound);
    BtnGoogleLogin = (Button) findViewById(R.id.BtnGoogleLogin);

    //Intializing Other Classes

    Animation mAnimation;

    mAnimation = new ScaleAnimation(0.9f,1.5f,0.9f,1.5f,Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.45f);
    mAnimation.setDuration(300);
    mAnimation.setRepeatCount(-1);
    mAnimation.setRepeatMode(Animation.REVERSE);
    mAnimation.setInterpolator(new AccelerateInterpolator());




    Typeface tf = Typeface.createFromAsset(getAssets(), "Obelus.ttf");

    //Initializing all Visual Objects
    final Button BtnPlay = (Button) findViewById(R.id.BtnPlay);
    final Button BtnSettings = (Button) findViewById(R.id.BtnSettings);
    final TextView BrainEfficieny = (TextView) findViewById(R.id.TxtBrainFactor);
    final TextView label = (TextView) findViewById(R.id.label);

    BtnPlay.setBackgroundResource(R.drawable.button1);
    BtnSettings.setBackgroundResource(R.drawable.button1);

    BtnPlay.setTypeface(tf);
    BtnSettings.setTypeface(tf);
    BrainEfficieny.setTypeface(tf);
    label.setTypeface(tf);

    BrainEfficieny.clearAnimation();
    BrainEfficieny.startAnimation(mAnimation);

    BrainEfficieny.setText(brainEfficiency + "%");

    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(Games.API)
            .build();





}

@Override
public void onStart(){
    super.onStart();
        mGoogleApiClient.connect();
Log.d("Train your Brain", "Value : " +  mGoogleApiClient.isConnected());
}

    //PLAY LISTENER

public void onStartClick(View v) {
    buttonSound.start();

    GameScreen gameScreen = new GameScreen();
    Intent IntentGameScreen = new Intent(TitleScreen.this, gameScreen.getClass());

    //Deactivate Music
    song1.stop();

    IntentGameScreen.putExtra("level", 1);
    IntentGameScreen.putExtra("path", this.getBaseContext().getFilesDir().getPath());
    IntentGameScreen.putExtra("muted", muted);

    TitleScreen.this.startActivity(IntentGameScreen);
    finish();

}

public void onGoogleLoginClick(View v){
    mSignInClicked = true;
    mGoogleApiClient.connect();
}

public void onSoundClick(View v){

    buttonSound.start();

    if (muted){
        muted = false;
        song1.start();

        //song1.seekTo(length); unused cause im using a loop

        BtnSound.setBackgroundResource(R.drawable.sound);

    }else{
        muted = true;
        song1.pause();

        //length = song1.getCurrentPosition();

        BtnSound.setBackgroundResource(R.drawable.no_sound);
    }

}

public void onConnectionFailed(ConnectionResult connectionResult){
    if(mResolvingConnectionFailure){
        return;
    }
    if (mSignInClicked || mAutoStartSignInflow) {
        mAutoStartSignInflow = false;
        mSignInClicked = false;
        mResolvingConnectionFailure = true;

    }

}


@Override
public void onConnected(@Nullable Bundle bundle) {

}

@Override
public void onConnectionSuspended(int i) {

}

您如何看到我在登录后正在调用登录我正在调用一个日志方法,它只是输出 FALSE。所以我其实不知道问题出在哪里。

【问题讨论】:

    标签: java android android-studio google-api google-api-client


    【解决方案1】:

    认为您需要为此添加登录 API

    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(Games.API)
            .addApi(Auth.GOOGLE_SIGN_IN_API, gso)
            .build();
    

    和之前的google登录选项

    GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                .requestScopes(new Scope(Scopes.PLUS_LOGIN))
                .requestEmail()
                .requestProfile()
                .build();
    

    以下是谷歌关于如何实现登录的一些示例 https://github.com/googlesamples/google-services/blob/master/android/signin/app/src/main/java/com/google/samples/quickstart/signin/SignInActivity.java

    【讨论】:

    • 这是 gplus 登录的登录代码。我想通过 Games.API 登录
    猜你喜欢
    • 1970-01-01
    • 2021-07-17
    • 1970-01-01
    • 2015-04-11
    • 1970-01-01
    • 2020-03-01
    • 2017-05-07
    • 2015-11-30
    • 1970-01-01
    相关资源
    最近更新 更多