【发布时间】:2016-01-10 18:48:48
【问题描述】:
目前,我正在从 API Client Library for Java 迁移到 Drive API for Android
但是,与 Java 的 API 客户端库 相比,我意识到 Drive API for Android 的帐户选择器非常慢。 有时,等待时间长达 5 秒。
非常快(Java 的 API 客户端库)
private static final GoogleAccountCredential googleAccountCredential = GoogleAccountCredential.usingOAuth2(context,
Arrays.asList(
DriveScopes.DRIVE_APPDATA,
// Legacy. Shall be removed after a while...
DriveScopes.DRIVE
)
);
startActivityForResult(googleAccountCredential.newChooseAccountIntent(), RequestCode.REQUEST_ACCOUNT_PICKER_LOAD_FROM_CLOUD);
此帐户选择器几乎立即出现。
非常慢(适用于 Android 的 Drive API)
GoogleApiClient mGoogleApiClient = new GoogleApiClient.Builder(context)
.addApi(Drive.API)
.addScope(Drive.SCOPE_APPFOLDER) // required for App Folder sample
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
mGoogleApiClient.connect();
@Override
public void onConnectionFailed(ConnectionResult result) {
Log.i(TAG, "GoogleApiClient connection failed: " + result.toString());
if (!result.hasResolution()) {
// show the localized error dialog.
GoogleApiAvailability.getInstance().getErrorDialog(this, result.getErrorCode(), 0).show();
return;
}
try {
result.startResolutionForResult(this, REQUEST_CODE_RESOLUTION);
} catch (SendIntentException e) {
Log.e(TAG, "Exception while starting resolution activity", e);
}
}
通常,当我第一次调用帐户选择器时,需要等待很长时间。有时,等待时间可能长达 5 秒。
我了解我们的应用程序代码通过 IPC 调用 Google Play 服务。因此,可能会有一些缓慢。不过,我预计它不会慢到 5 秒。
有什么办法可以让帐户选择器 UI 尽快出现吗?
【问题讨论】:
-
已经讨论过here already。尝试将帐户选择器 (startActivityForResult(....)) 与“setAccountName(email)”一起使用。我没有遇到任何延误。
-
谢谢。使用
startActivityForResult的帐户选择器我也不会遇到延迟。你有没有尝试过使用result.startResolutionForResult来显示帐户选择器?您是否遇到任何延迟?因为我不确定延迟是否仅发生在我的设备中,或者这是一种常见情况。谢谢。
标签: android google-play-services google-drive-android-api