/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class CheckFolderGoogleDrive
{
{
// controllo se esiste la cartella dell'applicazione
GoogleApiClient mGoogleApiClient = oActivity.getGoogleApiClient();
DriveFolder root = Drive.DriveApi.getRootFolder(mGoogleApiClient);
Query query = new Query.Builder()
.addFilter(Filters.eq(SearchableField.TITLE, sNameFolderGoogleDrive))
.addFilter(Filters.eq(SearchableField.TRASHED, false))
.build();
root.queryChildren(mGoogleApiClient, query).setResultCallback(metadataSearchFolderCallback);
}
final private ResultCallback<DriveApi.MetadataBufferResult> metadataSearchFolderCallback = new
ResultCallback<DriveApi.MetadataBufferResult>() {
@Override
public void onResult(DriveApi.MetadataBufferResult result) {
if (!result.getStatus().isSuccess()) {
try { throw new Exception("Problem while retrieving files"); } catch (Exception e
) { Log.
d(MainActivity.
CODE_LOG,
"" + e.
getMessage()); } return;
}
GoogleApiClient mGoogleApiClient = (oActivity).getGoogleApiClient();
MetadataBuffer buffer = result.getMetadataBuffer();
Log.d(TAG, "Folder count " + buffer.getCount());
if (buffer.getCount() == 0) {
// creo la cartella in google drive
} else {
// ho già la cartella
}
}
};
}
}
LyogcGFja2FnZSB3aGF0ZXZlcjsgLy8gZG9uJ3QgcGxhY2UgcGFja2FnZSBuYW1lISAqLwoKaW1wb3J0IGphdmEudXRpbC4qOwppbXBvcnQgamF2YS5sYW5nLio7CmltcG9ydCBqYXZhLmlvLio7CgovKiBOYW1lIG9mIHRoZSBjbGFzcyBoYXMgdG8gYmUgIk1haW4iIG9ubHkgaWYgdGhlIGNsYXNzIGlzIHB1YmxpYy4gKi8KY2xhc3MgQ2hlY2tGb2xkZXJHb29nbGVEcml2ZQp7CglwdWJsaWMgc3RhdGljIHZvaWQgbWFpbiAoU3RyaW5nW10gYXJncykgdGhyb3dzIGphdmEubGFuZy5FeGNlcHRpb24KCXsKCgkJLy8gY29udHJvbGxvIHNlIGVzaXN0ZSBsYSBjYXJ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gICAgIHRyeSB7IHRocm93IG5ldyBFeGNlcHRpb24oIlByb2JsZW0gd2hpbGUgcmV0cmlldmluZyBmaWxlcyIpOyB9IGNhdGNoIChFeGNlcHRpb24gZSkgeyBMb2cuZChNYWluQWN0aXZpdHkuQ09ERV9MT0csICIiICsgZS5nZXRNZXNzYWdlKCkpOyB9CiAgICAgICAgICAgICAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgICAgICAgICAgICB9CgogICAgICAgICAgICAgICAgICAgIEdvb2dsZUFwaUNsaWVudCBtR29vZ2xlQXBpQ2xpZW50ID0gKG9BY3Rpdml0eSkuZ2V0R29vZ2xlQXBpQ2xpZW50KCk7CiAgICAgICAgICAgICAgICAgICAgTWV0YWRhdGFCdWZmZXIgYnVmZmVyID0gcmVzdWx0LmdldE1ldGFkYXRhQnVmZmVyKCk7CiAgICAgICAgICAgICAgICAgICAgTG9nLmQoVEFHLCAiRm9sZGVyIGNvdW50ICAiICsgYnVmZmVyLmdldENvdW50KCkpOwoKICAgICAgICAgICAgICAgICAgICBpZiAoYnVmZmVyLmdldENvdW50KCkgPT0gMCkgewoKICAgICAgICAgICAgICAgICAgICAgICAgLy8gY3JlbyBsYSBjYXJ0ZWxsYSBpbiBnb29nbGUgZHJpdmUKCgogICAgICAgICAgICAgICAgICAgIH0gZWxzZSB7CgogICAgICAgICAgICAgICAgICAgICAgICAvLyBobyBnacOgIGxhIGNhcnRlbGxhCgoKICAgICAgICAgICAgICAgICAgICB9CgogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9OwoJfQkKCQoKfQ==