api - Android GoogleApiClient: Can't connect -
i'm trying implement new googleapiclient
android application, googleapiclient
can't connect. use connect()
method, isconnecting()
method returns true , isconnected()
never true.
my code
init
mgoogleapiclient = new googleapiclient.builder(this) .addapi(games.api).addscope(games.scope_games) .addconnectioncallbacks(this) .addonconnectionfailedlistener(this) .build();
connect
@override protected void onstart() { super.onstart(); if( mgoogleapiclient != null ) mgoogleapiclient.connect() }
open leaderboard
private void openachievements() { if( !mgoogleapiclient.isconnected() ) // false return; startactivityforresult(games.achievements.getachievementsintent(mgoogleapiclient), request_achievements); }
implements:
@override public void onconnected(bundle bundle) { log.e("debug", "connected!"); } @override public void onconnectionsuspended(int i) { log.e("debug", "connection suspended"); } @override public void onconnectionfailed(connectionresult connectionresult) { log.e("debug", "connection failed"); }
permissions:
<uses-permission android:name="android.permission.internet"/> <uses-permission android:name="android.permission.access_network_state"/>
meta-data:
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> <meta-data android:name="com.google.android.gms.games.app_id" android:value="@string/app_id" />
can help?
when you're building api client you're adding connection callbacks , in case it's activity implementing these callbacks.
and 1 of methods activity should implement onconnected()
called when connection established. need call openachievements()
method. , can remove unnecessary check !mgoogleapiclient.isconnected()
Comments
Post a Comment