use*_*714 7 android google-drive-api google-play-services google-drive-android-api
我开发了一个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();
}
}
Run Code Online (Sandbox Code Playgroud)
解决方法是什么?我需要在不保存设备帐户的情况下登录谷歌帐户(实际上只能访问驱动器).我只需要在完成后登录并注销,而不会在设备上留下任何个人信息.我该怎么做?
这不可能。只有在设备上注册的帐户(由用户自己验证)才能选择/使用连接到 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();
Run Code Online (Sandbox Code Playgroud)
(请注意.setAccountName([SOME_EMAIL@GMAIL.COM])),电子邮件仍然必须是设备注册帐户之一。该应用程序无法处理用户未经身份验证的任何帐户,这将是安全禁忌,对吗?
祝你好运
| 归档时间: |
|
| 查看次数: |
5973 次 |
| 最近记录: |