如何强制Android应用仅使用某个帐户才能使用google drive api(GDAA)?

时间:2016-08-04 14:37:57

标签: android google-drive-android-api

我正在开发一个生成文件的Android应用程序,我需要将这些文件上传到谷歌驱动器,但只使用特定帐户。有没有办法做到这一点?

现在我有了这个代码,允许我选择帐户:

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addApi(Drive.API)
            .addScope(Drive.SCOPE_FILE)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .build();

}
 @Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
    if (connectionResult.hasResolution()) {
        try {
            connectionResult.startResolutionForResult(this, RESOLVE_CONNECTION_REQUEST_CODE);
        } catch (IntentSender.SendIntentException e) {
            // Unable to resolve, message user appropriately
        }
    } else {
        GooglePlayServicesUtil.getErrorDialog(connectionResult.getErrorCode(), this, 0).show();
    }
}

提前致谢

1 个答案:

答案 0 :(得分:0)

没有。 GoogleApiClient使用设备上的Google帐户进行连接,因此Drive Android API只能在这些帐户上获取/创建文件。根据定义,如果您希望所有客户端备份到单个云端硬盘帐户,则所有这些客户端都应具有该帐户的凭据,这是不安全的。

听起来您需要一个服务器端点,您的客户端可以连接并发布任何数据。如果您需要预先解决的解决方案,请查看firebase(https://firebase.google.com/docs/storage/)提供的存储API。

相关问题