0

Is there any way to set the Metadata Description?

https://developer.android.com/reference/com/google/android/gms/drive/Metadata.html#getDescription()

If so, what is the length limit?

I can't see anything in the api: https://developer.android.com/reference/com/google/android/gms/drive/MetadataChangeSet.Builder.html

Mark
  • 7,446
  • 5
  • 55
  • 75

1 Answers1

1

Unfortunately not at the moment, AFAIK. What I do right now is initializing both GDAA and RESTful API (see the 'trash solution' SO 22295903) like this:

  private GoogleApiClient _gac;
  private com.google.api.services.drive.Drive _svc;
  public GoogleApiClient init(String email){
    _gac = new GoogleApiClient.Builder(UT.ACTX).addApi(com.google.android.gms.drive.Drive.API)
      .addScope(com.google.android.gms.drive.Drive.SCOPE_FILE).setAccountName(email).build();

    com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential crd =
     GoogleAccountCredential.usingOAuth2(UT.ACTX, 
                            Arrays.asList(com.google.api.services.drive.DriveScopes.DRIVE_FILE));
    crd.setSelectedAccountName(email);  
    _svc = new com.google.api.services.drive.Drive.Builder(
                            AndroidHttp.newCompatibleTransport(), new GsonFactory(), crd).build();
    return this;
  }

You get the description from DGAA (GoogleApiClient _gac above), but update/write it to RESTFul like this (off UI thread):

  public void oldDescUpW(String titl, String mime, String desc) {
    try {
      final FileList gLst = _svc.files().list()
         .setQ("title = '"+titl+".jpg' and mimeType = '"+mime+"' and trashed = false")
         .setFields("items(id)").execute();
      if (gLst.getItems().size() == 1) {
        final String sId = gLst.getItems().get(0).getId();
        com.google.api.services.drive.model.File body = 
                                                new com.google.api.services.drive.model.File();
        body.setDescription(desc);
      _svc.files().patch(sId, body).execute();
      }
    } catch (Exception e) {} 
  }    

It is also possible to use 'resource ID' from GDAA to address the file in RESTful, but it is not always immediately available (if the file is created in GDAA). See SO 22874657

DISCLAIMER:

It is a HACK and should not stay alive past GDAA delivery of an alternative.

Community
  • 1
  • 1
seanpj
  • 6,735
  • 2
  • 33
  • 54
  • Thanks. Loosely related: how does authentication work here? Does it need to happen twice: once for DGAA and once for RESTful? – Mark Apr 07 '14 at 17:20
  • I get through the GDAA authentication in the app entry calling 'connect()' that gets back as 'onConnectionFailed()'. Invoke the account picker using 'startResolutionForResult()', when it gets back in 'onActivityResult()' I GRAB THE ACCOUNT/EMAIL, THERE IS NO OTHER WAY TO GET IT LATER (SO 22865630). And it goes to 'connect()' again... No other auth for RESTful is necessary. See here: https://github.com/seanpjanson/EmailSwichActivity/blob/master/EmailSwitchActivity.java – seanpj Apr 07 '14 at 20:16
  • I tried that before, but the actual intent object was null. Could it be because I didn't have the GET_ACCOUNTS permission? That's interesting that the GDAA auth also does the for the RESTful API. No idea how that works, but if that's the way it's supposed to work, then that's all that matters I guess. – Mark Apr 08 '14 at 11:06