I'm having trouble with Google Drive API on my Android app. On my device, a Nexus 4 with Android 5.1.1 it's working fine. On my user's devices, the consent screen I had configured is not showing, instead, just a list selection dialog with the user's e-mail is showing, but it doesn't do anything.
I saw this issue on tree other devices with Android 5.0.1.
I configured the OAuth 2.0 credentials with my production SHA1 key and the consent screen. Like I said, it's working fine on my device.
I'm using the following parameters to compile my app:
- minSdkVersion=15
- targeSdKVerion=22
- compileSdkVersion=22
- Build Tools: 22.0.1
- Platform Tools: 23rc3
And these google libs:
- com.android.support:support-v4:22.2.0
- com.android.support:appcompat-v7:22.2.0
- com.android.support:design:22.2.0
- com.google.android.gms:play-services-ads:7.5.0
- com.google.android.gms:play-services-drive:7.5.0
Thank you!
Here is how my code looks now:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE_RESOLUTION) {
if (resultCode == RESULT_OK) {
// Make sure the app is not already connected or attempting to connect.
if (!mBackupAsyncTask.getGoogleApiClient().isConnecting() &&
!mBackupAsyncTask.getGoogleApiClient().isConnected()) {
// Connect and execute the task.
mBackupAsyncTask.getGoogleApiClient().connect();
}
}
}
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
Log.i(LOG_TAG, "GoogleApiClient connection failed: " + connectionResult.toString());
if (!connectionResult.hasResolution()) {
Log.i(LOG_TAG, "Error with no resolution.");
// Show the localized error dialog.
GooglePlayServicesUtil.getErrorDialog(connectionResult.getErrorCode(), this, 0).show();
} else {
// The failure has a resolution. Resolve it.
// Called typically when the app is not yet authorized, and an authorization
// dialog is displayed to the user.
try {
connectionResult.startResolutionForResult(this, REQUEST_CODE_RESOLUTION);
} catch (IntentSender.SendIntentException e) {
Log.e(LOG_TAG, "Exception while starting resolution activity.", e);
}
}
}
public class DriveBackupAsyncTask extends ApiClientAsyncTask<Object, Void, Metadata> {
public DriveBackupAsyncTask(Context context) {
super(context);
}
@Override
protected void onPreExecute() {
super.onPreExecute();
mProgressBar.setIndeterminate(true);
mEfetuarBackupButton.setEnabled(false);
mRestaurarBackupButton.setEnabled(false);
}
@Override
protected Metadata doInBackgroundConnected(Object... params) {
if (params[0].equals(TASK_BACKUP)) {
DriveFile backupFile = DriveBackupHelper.createBackup(
getGoogleApiClient(),
APP_FOLDER,
BACKUP_FILE,
getDbFile());
if (backupFile != null)
return backupFile.getMetadata(getGoogleApiClient()).await().getMetadata();
}
if (params[0].equals(TASK_RESTAURAR)) {
DriveFile backupFile = DriveBackupHelper.getBackupFile(
getGoogleApiClient(),
APP_FOLDER,
BACKUP_FILE);
if (backupFile == null)
return null;
if (DriveBackupHelper.restoreBackup(getGoogleApiClient(), getDbFile(), backupFile))
return backupFile.getMetadata(getGoogleApiClient()).await().getMetadata();
}
return null;
}
@Override
protected void onPostExecute(Metadata result) {
super.onPostExecute(result);
mProgressBar.setIndeterminate(false);
mEfetuarBackupButton.setEnabled(true);
mRestaurarBackupButton.setEnabled(true);
if (result == null) {
showError(getString(R.string.bkp_error));
} else {
showMessage(getString(R.string.bkp_success));
}
}
}