Reputation: 1632
Using the latest android sdk I’m building an app for android marketplace. I need to login to play services for my game leaderboards and achievements. I have two activities. I load it play services in the first activity and can access it if connected in the second activity, I believe.
With my current code it attempts to connect into google play services, but gets caught in a handler that causes it to attempt to loop forever. Commented portion, it attempts to login one time then stops. So this is what I have for the launching activity:
Here is my Android Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:androd="http://schemas.android.com/apk/res-auto"
package="com.my.application.name"
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<!-- Add the following meta-data for devices running Google Play service. -->
<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"/>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
And Also, here is my Opening Screen:
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.games.Games;
import com.google.android.gms.plus.Plus;
public class openingScreen extends ActionBarActivity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener,
View.OnClickListener {
/* Request code used to invoke sign in user interactions. */
private static final int RC_SIGN_IN = 10004;
private boolean mResolvingConnectionFailure = false;
private boolean mAutoStartSignInflow = true;
private boolean mSignInClicked = false;
/* Client used to interact with Google APIs. */
private GoogleApiClient mGoogleApiClient;
/* A flag indicating that a PendingIntent is in progress and prevents
* us from starting further intents.
*/
private boolean mIntentInProgress;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_opening_screen);
// Create the Google Api Client with access to Plus and Games
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API).addScope(Plus.SCOPE_PLUS_LOGIN)
.addApi(Games.API).addScope(Games.SCOPE_GAMES)
.build();
}
@Override
protected void onStart() {
super.onStart();
mGoogleApiClient.connect();
}
@Override
protected void onStop() {
super.onStop();
if (mGoogleApiClient.isConnected()) {
Games.signOut(mGoogleApiClient);
mGoogleApiClient.disconnect();
}
}
...
@Override
public void onConnected(Bundle bundle) {
Toast.makeText(getApplicationContext(), "Welcome Back, To the Stage of History ", Toast.LENGTH_SHORT).show();
findViewById(R.id.sign_in_button).setVisibility(View.GONE);
findViewById(R.id.sign_out_button).setVisibility(View.VISIBLE);
}
@Override
public void onClick(View view) {
if (view.getId() == R.id.sign_in_button) {
mGoogleApiClient.connect();
} else if (view.getId() == R.id.sign_out_button) {
mGoogleApiClient.disconnect();
}
}
@Override
public void onConnectionFailed(ConnectionResult result) {
if (!mIntentInProgress && result.hasResolution()) {
try {
mIntentInProgress = true;
result.startResolutionForResult(this, // your activity
RC_SIGN_IN);
} catch (IntentSender.SendIntentException e) {
// The intent was canceled before it was sent. Return to the default
// state and attempt to connect to get an updated ConnectionResult.
Log.e("network", "onConnectionFailed: "+ String.valueOf(e));
mIntentInProgress = false;
mGoogleApiClient.connect();
}
}
}
@Override
public void onConnectionSuspended(int cause) {
mGoogleApiClient.connect();
}
protected void onActivityResult(int requestCode, int responseCode, Intent intent) {
if (requestCode == RC_SIGN_IN) {
mIntentInProgress = false;
if (!mGoogleApiClient.isConnecting()) {
Log.e("network", "forever connecting loop Failed: " + requestCode + " "+ intent);
// mGoogleApiClient.connect();
}
}
}
}
Keep in mind, I have also done the following:
The app tries to sign in to google play services and then fires the activityResult() callback:
Looking at my past logcat files the trace says 403 error Google Game Services Not Configured. As we can see from my code, the stack gives a response of client id not found but Its in the game-ids.xml like Google play api documentation said to do!
I’ve picked at this for too long, and this doesn't seem to matter because I was careful to only enter in the generated sha1 key for the production-release created apk. Stack Overflow, Please Help.
07-26 17:18:48.224 5126-4861/? E/SignInIntentService﹕ Access Not Configured. The API (Google Play Game Services API) is not enabled for your project. Please use the Google Developers Console to update your configuration. com.google.android.gms.games.server.error.GamesException at com.google.android.gms.games.server.GamesServer.getResponseBlocking(GamesServer.java:156) at com.google.android.gms.games.broker.PlayerAgent.getPlayerFromNetwork(PlayerAgent.java:1737) at com.google.android.gms.games.broker.PlayerAgent.fetchPlayer(PlayerAgent.java:623) at com.google.android.gms.games.broker.DataBroker.loadSelf(DataBroker.java:828) at com.google.android.gms.games.service.PlayGamesSignInIntentService$LoadSelfOperation.executeInternal(PlayGamesSignInIntentService.java:366) at com.google.android.gms.games.service.PlayGamesSignInIntentService$BaseOperation.execute(PlayGamesSignInIntentService.java:52) at com.google.android.gms.games.service.PlayGamesSignInIntentService$OperationAdapter.execute(PlayGamesSignInIntentService.java:451) at com.google.android.gms.chimera.BaseAsyncOperationService$OperationTask.run(BaseAsyncOperationService.java:179) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573) at java.lang.Thread.run(Thread.java:841) 07-26 17:18:48.234 32016-32016/? E/LoadSelfFragment﹕ Unable to sign in - application does not have a registered client ID
Upvotes: 1
Views: 856
Reputation: 1632
The Culprit was that I am forced to sideload a signed version of it only. I cannot use the developer build that gets generated onto my device. Using the android file transfer and uninstalling my device manually using the application settings menu allowed me to get the signed version installed. Having the signed version installed and uploaded to the play developer console seems to allow me to sign in!
I've also come to realize that my approach was in vain. As it turns out I cannot seem to carry over my connection from activity to activity as I once thought. I'm now in the process of refactoring my code to work with activities as I can't seem to wrangle the visibility:gone or visible: properly with click events.
Upvotes: 1