Log in to Google on Android device without adding google account to device

I am developing an Android application that should allow read and write access to Google Drive. In addition, it must work on public devices (this means that many people can use the same device to access their Google account). In such circumstances, it is unacceptable to add each user account to Android Account Manager. Unfortunately, all official manuals use authentication with the google account registered on the device. A pop-up window will appear to select existing google accounts from the device or add a new one.

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 disk) without saving the account on the device. I just need to log in and log out when done, without leaving any personal data on the device. How can i do this?

+5
source share
1 answer

It's impossible. To connect to GooDrive, only accounts registered on the device (certified by the users themselves) can be selected / used. Even if you can use a construct, for example:

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

(please pay attention to .setAccountName ([ SOME_EMAIL@GMAIL.COM ]) ), the letter should still be one of the devices registered on the device. The application cannot address any accounts that the user did not authenticate himself, would it be no-no security, right?

Luck

+1
source

Source: https://habr.com/ru/post/1233956/


All Articles