我在Android应用中遇到了Google Drive API问题。在我的设备上,使用Android 5.1.1的Nexus 4工作正常。在我用户的设备上,我没有显示我配置的同意屏幕,相反,用户的电子邮件只显示一个列表选择对话框,但它没有任何作用。Android Google Drive API身份验证
我在Android 5.0.1的其他设备上看到了这个问题。
我使用我的生产SHA1密钥和同意屏幕配置了OAuth 2.0凭据。就像我说的,它在我的设备上工作正常。
我用下面的参数来编译我的应用程序:
- 的minSdkVersion = 15
- targeSdKVerion = 22
- compileSdkVersion = 22
- 生成工具:22.0.1
- 平台工具:23rc3
而这些谷歌图书馆:
- 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:播放服务的广告:7.5.0
- com.google.android.gms:播放服务驱动:7.5.0
谢谢!
这里是我的代码现在的样子:
@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));
}
}
}
是否要求用户选择一个帐户的对话框?如果手机上有多个Google帐户,并且您没有使用'useDefaultAccount()'构建GoogleApiClient,则会显示一个对话框,要求用户选择一个帐户。你说对话“什么都不做”。你能提供更多细节吗? –
是的,是要求用户选择一个帐户的对话框。当用户选择一个帐户时,没有任何反应。 我没有使用useDefaultAccount选项构建我的客户端。 –
实际上,即使用户只有一个帐户,也会显示此对话框。 –