我开发了一个Android应用程序,需要允许对用户的谷歌驱动器进行读/写访问。此外,它应该在公共设备上运行(意味着许多人可能使用相同的设备访问他们的谷歌驱动器帐户)。在这种情况下,将每个用户的帐户添加到Android客户经理是不可接受的。不幸的是,所有官方指南都使用在设备上注册的Google帐户进行身份验证。 将显示从设备中选择现有Google帐户或添加新帐户的弹出窗口。
protected void onStart() {
super.onStart();
if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
// Optionally, add additional APIs and scopes if required.
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.build();
}
mGoogleApiClient.connect();
}
/**
* Called when {@code mGoogleApiClient} is trying to connect but failed.
* Handle {@code result.getResolution()} if there is a resolution
* available.
*/
@Override
public void onConnectionFailed(ConnectionResult result) {
Log.i(TAG, "GoogleApiClient connection failed: " + result.toString());
if (!result.hasResolution()) {
// Show a localized error dialog.
GooglePlayServicesUtil.getErrorDialog(
result.getErrorCode(), this, 0, new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
retryConnecting();
}
}).show();
return;
}
// If there is an existing resolution error being displayed or a resolution
// activity has started before, do nothing and wait for resolution
// progress to be completed.
if (mIsInResolution) {
return;
}
mIsInResolution = true;
try {
result.startResolutionForResult(this, REQUEST_CODE_RESOLUTION);
} catch (SendIntentException e) {
Log.e(TAG, "Exception while starting resolution activity", e);
retryConnecting();
}
}
解决方法是什么?我需要在不保存设备帐户的情况下登录谷歌帐户(实际上只能访问驱动器)。我只需要在完成后登录并注销,而不会在设备上留下任何个人信息。 我该怎么办?
答案 0 :(得分:1)
这是不可能的。只有在设备上注册的帐户(由用户自己验证)才能被选择/用于连接到GooDrive。即使你可以使用像:
这样的结构mGoogleApiClient = new GoogleApiClient.Builder(this)
.addApi(Drive.API)
.addScope(Drive.SCOPE_FILE)
// Optionally, add additional APIs and scopes if required.
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.setAccountName([SOME_EMAIL@GMAIL.COM])
.build();
(请注意 .setAccountName([SOME_EMAIL@GMAIL.COM])),该电子邮件仍然是设备注册帐户之一。该应用无法解决用户自己未经过身份验证的任何帐户,这不是安全问题,对吧?
祝你好运