Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LogIn to google drive on android without adding the google account to the device

I develop an android application that needs to allow read/write access to user's google drive. In addition, it is supposed to run on public devices (meaning that many people might use same device to access their google drive account). In such circumstances, it is unacceptable to add each user's account to Android Account Manager. Unfortunately, all official guides, use the authentication with the google account registered on device. The popup of selecting existing google accounts from device or adding a new one appears.

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();
        }
    }

What is the workaround? I need to login to google account (actually only to the drive) without saving the account on the device. I just need to login and logout when finished, without leaving any personal info on the device. How can I do it?

like image 849
user2924714 Avatar asked Oct 18 '15 09:10

user2924714


People also ask

Can you access a Google Drive without a Google account?

Share the File or Folder Through LinkNon-Gmail users can access Google Drive files and folders via a link sent to them. Right-click the file or folder and click Share > Get link. Then, click Restricted and select Anyone with the link.

Can a person without Gmail account access Google Drive?

Google Accounts don't have to use a gmail.com address. You can associate any existing email address with a Google Account. Alternatively, files can be shared with non-Google accounts using visitor sharing.

Can you use an Android device without a Google account?

(Note: Using the Android Market requires signing in with a Google account. That's just unavoidable. There are work-arounds, like finding the . apk files for these apps around the web, or looking for them in Amazon's Appstore for Android, but you could also create a Google account just for this purpose alone.


1 Answers

It is not possible. Only accounts registered on the device (authenticated by users themself) can be selected/used to connect to GooDrive. Even if you can use construct like:

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([[email protected]])
                    .build();

(please notice the .setAccountName([[email protected]])), the email still HAS TO BE one of the device registered accounts. The app can't address any accounts the user her/himself did not authenticate, it would be security no-no, right?

Good Luck

like image 79
seanpj Avatar answered Oct 03 '22 11:10

seanpj