mercredi 22 avril 2015

Can't connect my app with google play games

I am trying to connect my application to the google play games services. I show somes of messages to debug the app. But when I try to connect with google play games it show that connection is wrong. Someone know where is the problem?

public class MenuActivity extends ActionBarActivity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
    AdView adView;

    GoogleApiClient mGoogleApiClient;

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

        android.support.v7.app.ActionBar ab = getSupportActionBar();
        ab.setBackgroundDrawable(getResources().getDrawable(R.drawable.background_tile_actionbar));

        //CONECTANDO CON LA CUENTA DE GOOGLE API CLIENT
        mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addConnectionCallbacks(this)
                .addOnConnectionFailedListener(this)
                .addApi(Games.API).addScope(Games.SCOPE_GAMES).build();


        // Buscar AdView como recurso y cargar una solicitud.
        adView = (AdView)this.findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().build();
        adView.loadAd(adRequest);

    }

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

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

    @Override
    public void onPause() {
        adView.pause();
        super.onPause();
    }

    @Override
    public void onResume() {
        super.onResume();
        adView.resume();
    }

    @Override
    public void onDestroy() {
        adView.destroy();
        super.onDestroy();
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_menu, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    public void onClickJugar(View view){
        Intent intent;
        intent = new Intent(this,LevelsActivity.class);
        startActivity(intent);
    }

    public void onClickEstadisticas(View view){
        Intent intent;
        intent = new Intent(this,StatisticsActivity.class);
        startActivity(intent);
    }

    public void onClickRanking(View view){
        if(mGoogleApiClient.isConnected()){
            Toast toast = Toast.makeText(this,"Te has conectado a google play cuando has hecho click",Toast.LENGTH_SHORT);
            toast.show();
        }else{
            Toast toast = Toast.makeText(this,"No te has conectado a google play cuando has hecho click",Toast.LENGTH_SHORT);
            toast.show();
        }
    }

    @Override
    public void onConnected(Bundle bundle) {
        Toast toast = Toast.makeText(this,"Te has conectado a google play",Toast.LENGTH_SHORT);
        toast.show();
    }

    @Override
    public void onConnectionSuspended(int i) {
        Toast toast = Toast.makeText(this,"La conexion ha google play se ha suspendido",Toast.LENGTH_SHORT);
        toast.show();
    }

    @Override
    public void onConnectionFailed(ConnectionResult connectionResult) {
        Toast toast = Toast.makeText(this,"La conexion ha google play ha fracasado",Toast.LENGTH_SHORT);
        toast.show();
    }
}

Aucun commentaire:

Enregistrer un commentaire