My goal is to develop a game that allows to quiz music with friends. You can test it by yourself by registering to this Google+ community : https://plus.google.com/u/0/communities/100815426127955231967
I am testing my app on several devices :
- Motorola Xoom, android 4.1.2, build JZO54K
- Nexus 7 2012 Wifi "nagasi", android 5.0.2, build LRX22G
- Nexus 5, android 5.0.1, build LRX22C
I use the same Google user on all devices. My app is registered and I included the right lines in the manifest file.
With exactly the same code, I can succesfully connect to Google Plus and Games services on Nexus 7 and Nexus 5 lollipop devices, but not on Xoom android 4 device.
Here is the code, the connection request is in the Activity onCreate :
@Override
protected void onCreate(Bundle savedInstanceState) {
if (GooglePlayServicesUtil.isGooglePlayServicesAvailable(this) == ConnectionResult.SUCCESS) {
if (mGoogleApiClient == null) {
Plus.PlusOptions plusOptions = new Plus.PlusOptions.Builder().addActivityTypes(
"http://schemas.google.com/AddActivity", "http://schemas.google.com/ReviewActivity").build();
mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(Games.API).addScope(Games.SCOPE_GAMES)
.addApi(Plus.API, plusOptions).addScope(Plus.SCOPE_PLUS_LOGIN)
.addConnectionCallbacks(this).addOnConnectionFailedListener(this).build();
}
mGoogleApiClient.connect();
} else {
Toast.makeText(this, R.string.texteErreurGPlus, Toast.LENGTH_LONG).show();
}
}
For Android 4 device, the onConnectionFailed callback is called with a message :
GoogleApiClient connection failed: ConnectionResult{statusCode=SIGN_IN_REQUIRED, resolution=PendingIntent{412f07c8: android.os.BinderProxy@413b0bd0}} :
@Override
public void onConnectionFailed(ConnectionResult result) {
if (mResolvingConnectionFailure) {
// Already resolving
return;
} else if (result.hasResolution()) {
try {
mResolvingConnectionFailure = true;
result.startResolutionForResult(this, REQUEST_CODE_RESOLUTION);
} catch (SendIntentException e) {
// There was an error with the resolution intent. Try again.
mGoogleApiClient.connect();
}
} else {
// Show dialog using GooglePlayServicesUtil.getErrorDialog()
showErrorDialog(result.getErrorCode());
mResolvingConnectionFailure = true;
}
}
This leads to activity onActivityResult :
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case REQUEST_CODE_RESOLUTION:
mResolvingConnectionFailure = false;
if (resultCode == RESULT_OK) {
// Make sure the app is not already connected or attempting to connect
if (!mGoogleApiClient.isConnecting() &&
!mGoogleApiClient.isConnected()) {
mGoogleApiClient.connect();
}
} else {
mGoogleApiClient.connect();
}
break;
and an infinite loop because resultCode is not equal to RESULT_OK.
Here is the gradle file for Android Studio :
apply plugin: 'android'
android {
compileSdkVersion 21
buildToolsVersion '21.1.2'
defaultConfig {
applicationId "debut.blindtest"
minSdkVersion 16
targetSdkVersion 21
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
}
dependencies {
compile project(':volley')
compile 'com.android.support:appcompat-v7:21.0.2'
compile 'com.google.android.gms:play-services-plus:6.5.+'
compile 'com.google.android.gms:play-services-games:6.5.+'
compile files('libs/deezer-sdk-0.10.16.jar')
}
The execution flow is :
- main activity onCreate where GoogleApiClient connect is called
- main activity onConnectionFailed called, result has resolution, so result.startResolutionForResult is called
- main activity onActivityResult is called
The exception:
01-07 22:38:01.260 4894-4894/debut.blindtest I/TagApplicationBlindTest﹕ onActivityResult : REQUEST_CODE_RESOLUTION : resultCode : 0
01-07 22:38:01.280 4935-4936/? D/dalvikvm﹕ GC_CONCURRENT freed 448K, 7% free 6800K/7303K, paused 24ms+3ms, total 55ms
01-07 22:38:01.280 4935-4935/? D/dalvikvm﹕ WAIT_FOR_CONCURRENT_GC blocked 22ms
01-07 22:38:01.280 4894-4894/debut.blindtest E/BaseGamesUtils﹕ No standard error dialog available. Making fallback dialog.
01-07 22:38:01.380 4864-4864/? W/dalvikvm﹕ VFY: unable to find class referenced in signature (Landroid/app/SharedElementCallback;)
01-07 22:38:01.380 4864-4864/? I/dalvikvm﹕ Could not find method android.app.Activity.setEnterSharedElementCallback, referenced from method android.support.v4.app.q.setEnterSharedElementCallback
01-07 22:38:01.380 4864-4864/? W/dalvikvm﹕ VFY: unable to resolve virtual method 80: Landroid/app/Activity;.setEnterSharedElementCallback (Landroid/app/SharedElementCallback;)V
01-07 22:38:01.380 4864-4864/? D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x000e
01-07 22:38:01.380 4864-4864/? W/dalvikvm﹕ VFY: unable to find class referenced in signature (Landroid/app/SharedElementCallback;)
01-07 22:38:01.380 4864-4864/? I/dalvikvm﹕ Could not find method android.app.Activity.setExitSharedElementCallback, referenced from method android.support.v4.app.q.setExitSharedElementCallback
01-07 22:38:01.380 4864-4864/? W/dalvikvm﹕ VFY: unable to resolve virtual method 81: Landroid/app/Activity;.setExitSharedElementCallback (Landroid/app/SharedElementCallback;)V
01-07 22:38:01.380 4864-4864/? D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x000e
01-07 22:38:01.380 4864-4864/? I/dalvikvm﹕ Could not find method android.app.Activity.finishAfterTransition, referenced from method android.support.v4.app.q.supportFinishAfterTransition
01-07 22:38:01.380 4864-4864/? W/dalvikvm﹕ VFY: unable to resolve virtual method 46: Landroid/app/Activity;.finishAfterTransition ()V
01-07 22:38:01.380 4864-4864/? D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0006
01-07 22:38:01.380 4864-4864/? I/dalvikvm﹕ Could not find method android.app.Activity.postponeEnterTransition, referenced from method android.support.v4.app.q.supportPostponeEnterTransition
01-07 22:38:01.380 4864-4864/? W/dalvikvm﹕ VFY: unable to resolve virtual method 77: Landroid/app/Activity;.postponeEnterTransition ()V
01-07 22:38:01.380 4864-4864/? D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0006
01-07 22:38:01.380 4864-4864/? I/dalvikvm﹕ Could not find method android.app.Activity.startPostponedEnterTransition, referenced from method android.support.v4.app.q.supportStartPostponedEnterTransition
01-07 22:38:01.380 4864-4864/? W/dalvikvm﹕ VFY: unable to resolve virtual method 89: Landroid/app/Activity;.startPostponedEnterTransition ()V
01-07 22:38:01.380 4864-4864/? D/dalvikvm﹕ VFY: replacing opcode 0x6e at 0x0006
01-07 22:38:01.410 4894-4898/debut.blindtest D/dalvikvm﹕ GC_CONCURRENT freed 325K, 6% free 7193K/7623K, paused 14ms+38ms, total 115ms
01-07 22:38:01.410 4935-4936/? D/dalvikvm﹕ GC_CONCURRENT freed 460K, 8% free 6851K/7367K, paused 19ms+12ms, total 83ms
01-07 22:38:01.410 4935-4935/? D/dalvikvm﹕ WAIT_FOR_CONCURRENT_GC blocked 41ms
01-07 22:38:01.450 4864-4864/? E/dalvikvm﹕ Could not find class 'android.app.AppOpsManager', referenced from method com.google.android.gms.common.util.e.a
01-07 22:38:01.450 4864-4864/? W/dalvikvm﹕ VFY: unable to resolve check-cast 35 (Landroid/app/AppOpsManager;) in Lcom/google/android/gms/common/util/e;
01-07 22:38:01.450 4864-4864/? D/dalvikvm﹕ VFY: replacing opcode 0x1f at 0x0010
01-07 22:38:01.460 4864-4864/? E/SignInActivity﹕ SignInActivity must be started with startActivityForResult
01-07 22:38:01.530 4935-4936/? D/dalvikvm﹕ GC_CONCURRENT freed 457K, 7% free 6916K/7431K, paused 18ms+5ms, total 61ms
Could you help me to discover what I should do to be compatible with Android 4 devices ?