有什么方法可以让帐户选择器 UI 尽快出现
Is there any way make account picker UI appear as fast as possible
目前,我正在从 Java 的 API 客户端库迁移到 Drive API Android
但是,与 API Java 的客户端库相比,我从 Drive [=56] 实现了帐户选择器=] 对于 Android 非常慢。 有时,最多需要 5 秒的等待时间。
非常快(API Java 的客户端库)
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);
此帐户选择器几乎立即出现。
非常慢(驱动 API for Android)
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 尽快出现吗?
请尝试以下操作(我不使用 addScope
):
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestScopes(new Scope(Scopes.DRIVE_APPFOLDER))
.requestEmail()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.addApi(Drive.API)
.build();
帐户选择器出现得很快(我的phone:摩托罗拉,API 16)。
如@seanpj 在
中所述
startActivityForResult(AccountPicker.newChooseAccountIntent(null,
null, new String[]{GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE}, true, null, null, null, null),
REQ_ACCPICK);
会快很多。
其中一个原因是它没有在弹出对话框中显示您的个人资料图片。我相信那些个人资料图片需要网络活动,这使得过程很慢。
目前,我正在从 Java 的 API 客户端库迁移到 Drive API Android
但是,与 API Java 的客户端库相比,我从 Drive [=56] 实现了帐户选择器=] 对于 Android 非常慢。 有时,最多需要 5 秒的等待时间。
非常快(API Java 的客户端库)
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);
此帐户选择器几乎立即出现。
非常慢(驱动 API for Android)
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 尽快出现吗?
请尝试以下操作(我不使用 addScope
):
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestScopes(new Scope(Scopes.DRIVE_APPFOLDER))
.requestEmail()
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.addApi(Drive.API)
.build();
帐户选择器出现得很快(我的phone:摩托罗拉,API 16)。
如@seanpj 在
startActivityForResult(AccountPicker.newChooseAccountIntent(null,
null, new String[]{GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE}, true, null, null, null, null),
REQ_ACCPICK);
会快很多。
其中一个原因是它没有在弹出对话框中显示您的个人资料图片。我相信那些个人资料图片需要网络活动,这使得过程很慢。