Hello, such questions have already been, but still try to ask.
In the Android application, you must send the file to Google Drive. I tried to do this instruction .
- I registered the application in the developer console (you specify
sha1, the package name ...). Created andAPIkey andOAuth2.0 client ID - The official documentation suggests doing so:
in build.gradle:
compile 'com.google.android.gms:play-services-drive:8.4.0' in the manifest:
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> to connect to google drive:
mGoogleApiClient = new GoogleApiClient.Builder(this) .addApi(Drive.API) .addScope(Drive.SCOPE_FILE) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .build(); connection error:
@Override public void onConnectionFailed(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(); } } and further:
@Override protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) { switch (requestCode) { ... case RESOLVE_CONNECTION_REQUEST_CODE: if (resultCode == RESULT_OK) { mGoogleApiClient.connect(); } break; } } The problem is that I need to set up the program in order to select a Google account, save it, and then specify it when accessing to access the disk. I tried to add .setAccountName(имя_аккаунта_из_настроек) when creating a client, but this option does not roll, the isConnected() after connect() is false .
I select the account in the settings as follows:
Intent googlePicker = AccountPicker.newChooseAccountIntent(null, null, new String[] { GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE }, true, null, null, null, null); mActivity.startActivityForResult(googlePicker, PICK_ACCOUNT_REQUEST); here mActivity is the mActivity (program settings) from which I call the window with accounts.
Please tell me how to implement the ability to connect to the Google disk without having to call the account selection window when connecting to the disk, and using the Google account specified in the program settings. And the account will be different, the one that the user added to the system (perhaps one of several). Now I can do it even if isConnected() = false , then sending to my disk, where I registered the application (console), is executed. There is no other account, and the connection error is always ConnectionResult{statusCode=SIGN_IN_REQUIRED ...
PS I’ve been working on this task for a long time, I tried it through the Google APIs Java Client, this option doesn’t work at all, I rummaged through a bunch of materials, I was already desperate to make this kind of simple function