So first of all I know that the DriveID for each file/folder is device specific, BUT the resourceId is constant and that's really what I'm using to test if the items are the same (besides the title of course).
Problem
I am trying to sync folders in my AppFolder across devices, however, I'm getting different files/folders on each device despite querying via the title before doing anything. So some code:
How I set up the api client
mGoogleApiClient = new GoogleApiClient.Builder(context.getApplicationContext())
.addApi(Drive.API)
.addApi(Plus.API)//used for logout process
.addScope(Drive.SCOPE_APPFOLDER)
.addConnectionCallbacks(OnConnection)
.addOnConnectionFailedListener(OnFailedListener)
.build();
How I set up the appFolder
appFolder = Drive.DriveApi.getAppFolder(mGoogleApiClient);
I have verified that I'm getting the same resourceId for the AppFolder on both devices.
How I create/get the folders
private static DriveFolder CheckForOrCreateDriveFolder(DriveFolder appFolder, String folder) {
MetadataBuffer metadataBuffer = appFolder.queryChildren(mGoogleApiClient, new Query.Builder().addFilter(Filters.eq(SearchableField.TITLE, folderName)).build()).await().getMetadataBuffer();
if(metadataBuffer != null&&metadataBuffer.getCount()>0) {
Log.v(TAG,"Found "+metadataBuffer.getCount()+" existing folders");
Metadata metadata = metadataBuffer.get(0);
if (metadata != null && metadata.isFolder()) {
Log.v(TAG,"Returning existing folder");
return Drive.DriveApi.getFolder(mGoogleApiClient, metadata.getDriveId());
}else{
Log.v(TAG,"Returning created folder even though we found meta data");
return appFolder.createFolder(mGoogleApiClient, new MetadataChangeSet.Builder().setTitle(folderName).build()).await().getDriveFolder();
}
}else{
Log.v(TAG,"Returning created folder");
return appFolder.createFolder(mGoogleApiClient, new MetadataChangeSet.Builder().setTitle(folderName).build()).await().getDriveFolder();
}
}
On this I always get the expected result. I.E. Found 1 existing folders and then Returning existing folder. Also, before you mention the use of await() I'm spinning off my own threads and this is NEVER called on UI thread, so no worries.
Test code
I noticed that sqlite db wasn't copying over which then let to me figuring out that not even the folders were crossing over so I wrote another test:
DriveApi.MetadataBufferResult metadataBufferResult = appFolder.listChildren(mGoogleApiClient).await();
Log.v(TAG,"AppFolder Contents:");
for (Metadata metadata : metadataBufferResult.getMetadataBuffer()) {
Log.v(TAG,"MD:"+metadata.getTitle()+" : "+metadata.getDriveId().getResourceId()+" - "+(metadata.isFolder()?"is a folder":"is a file"));
}
Which for one device returns:
AppFolder Contents:
MD:itemImage : 1eFvDS6cWmCbgblahblahblahblahblah - is a folder
MD:itemAudio : 1c86N8AGRV8Bblahblahblahblahblah - is a folder
MD:userImage : 1LnsgFneT-l3ZYzMbblahblahblahblah - is a folder
MD:db.sqlite : 1DH4QfUfrsxDScblahblahblahblah - is a file
and for the other:
AppFolder Contents:
MD:itemAudio : 1CqeVASm_Gjjblahblahblahblahblah - is a folder
MD:itemImage : 1Djs059FYGSfOblahblahblahblahblah - is a folder
MD:userImage : 1U5c5yCw-XdfCblahblahblahblahblah - is a folder
MD:db.sqlite : 15qR3WLmvT3Nn2Ztblahblahblahblahblah - is a file
I've verified 4 times or more that these devices are using the same google account. If there is any other code or info I could give you to help please let me know! Any help finding an answer to this would be greatly appreciated^^ Thanks!