Cristina
Cristina

Reputation: 387

How use the Google Drive like a web Service

I'm trying to create an app and use the Google Drive like a webService to this app, I'll store some files in my Drive account (like images and audios), and when the user click in a button (of download), will be done the download of the chosen file to his phone. However when I try to connect to my Drive account, the app displays a dialog asking to user choose a account (of his phone), but I should inform my account programmatically (and the user should not have knowledge of it). Just press the button and that is it. Anyone please, knows how I should inform my account in my code:

My code:

@Override
    protected void onResume() {
        super.onResume();
        if (mGoogleApiClient == null) {
            mGoogleApiClient = new GoogleApiClient.Builder(this)
                    .addApi(Drive.API)
                    .addScope(Drive.SCOPE_FILE)
                    .addScope(Drive.SCOPE_APPFOLDER)
                    .addConnectionCallbacks(this)
                    .addOnConnectionFailedListener(this)
                    .build();
        }
        mGoogleApiClient.connect();//this will kick the code to onConnectionFailed() (cause no account was informed)
    }

and here on onConnectionFailed() is the code that opens the dialog

@Override
    public void onConnectionFailed(ConnectionResult result) {
        if (!result.hasResolution()) {
            Log.i(TAG, "Erro! " + result.toString());
            return;
        }

        try {
            //open the dialog
            result.startResolutionForResult(this, REQUEST_CODE_RESOLUTION);
        } catch (SendIntentException e) {

        }
    }

Anyone knows how and where I have to inform my account in order to directly set up my account and makes the dialog does not open

Thanks

Upvotes: 1

Views: 456

Answers (2)

Ethan
Ethan

Reputation: 2087

If you want to host files for your application online for free, I would actually use dropbox. There would be no prompt for the user (other than how they want to download it[which can also be avoided]) But all you have to do is download the file using the standard android downloader, and change the dropbox url from dropbox.com/... to dl.dropbox.com or user.dropbox.com (can't remember which, it's been a while. If you want to update the files, just drag them into you dropbox WITH THE SAME NAME as the old file, and they will be updated without changing their url. Hope this helps!

Upvotes: 0

Diego Torres Milano
Diego Torres Milano

Reputation: 69188

You can include and account name in Builder:

 GoogleApiClient client = new GoogleApiClient.Builder(this)
         .enableAutoManage(this /* FragmentActivity */,
             this /* OnConnectionFailedListener */)
         .addApi(Plus.API)
         .addScope(Plus.SCOPE_PLUS_LOGIN)
         .setAccountName("[email protected]")
         .build();

But this does not mean it's a good idea though.

Take a look at https://firebase.google.com/docs/storage/

Upvotes: 1

Related Questions