android - 在不将谷歌帐户添加到设备的情况下在安卓上登录谷歌驱动器

标签 android google-drive-api google-play-services google-drive-android-api

我开发了一个 android 应用程序,需要允许对用户的 google 驱动器进行读/写访问。此外,它应该在公共(public)设备上运行(这意味着许多人可能使用同一设备访问他们的谷歌驱动器帐户)。在这种情况下,将每个用户的帐户添加到 Android 帐户管理器是 Not Acceptable 。不幸的是,所有官方指南都使用设备上注册的谷歌帐户进行身份验证。 出现从设备中选择现有 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();
        }
    }

解决方法是什么?我需要登录到谷歌帐户(实际上只登录到驱动器)而不在设备上保存帐户。我只需要在完成后登录和注销,而不在设备上留下任何个人信息。 我该怎么做?

最佳答案

这是不可能的。只有在设备上注册的帐户(由用户自己验证)才能被选择/用于连接到 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])),电子邮件仍然必须是设备注册帐户之一。该应用无法解决用户未通过身份验证的任何帐户,这是安全禁忌,对吧?

祝你好运

关于android - 在不将谷歌帐户添加到设备的情况下在安卓上登录谷歌驱动器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33196147/

相关文章:

google-drive-api - 使用 OAuth 2.0 客户端 ID 限制 Google Project 中的帐户

android - 由于 StackOverflowError,构建失败并显示 com.google.gms :google-services:3. 2.0

android - 从 onPause 中的 fragment 中删除位置更新时发生内存泄漏

android - FCMListenerService 的两个实例

android - Gradle 没有指向指定的版本

android - 安卓内存不足异常

java - 使用 list 权限自动获取身份验证 token

android - 如何更改 android::CoordinatorLayout 屏幕

android - 将移动应用程序同步到 Android Wear

google-drive-api - Google云端硬盘服务帐户-查看其他帐户中的文件