By calling the Drive.About.Get API, your app can obtain a user's Drive information, such as its storage quota limit and maximum size of a file that can be uploaded by the user.
1. You have made all necessary preparations.
2. You have downloaded the client sample code and tried it out.
private Drive buildDrive() {
Drive service = new Drive.Builder(CredentialManager.getInstance().getCredential(), context).build();
return service;
} private About getAbout() {
About response = null;
try {
Drive drive = buildDrive();
Drive.About about = drive.about();
response = about.get().setFields("*").execute();
String res = response.toString();
} catch (Exception e) {
Log.e(TAG, "getInfo error: " + e.toString());
}
return response;
}
Call the About.Get in the subthread. The process of obtaining user information takes a while and requires an Internet connection.
/**
* Check whether the user needs to be prompted to update the protocol.
*
* @param about About response that is returned.
*/
private void checkUpdateProtocol(About about) {
if (about == null) {
return;
}
Log.d(TAG, "checkUpdate: " + about.toString());
Object updateValue = about.get("needUpdate");
boolean isNeedUpdate = false;
if (updateValue instanceof Boolean) {
isNeedUpdate = (Boolean) updateValue;
}
if (!isNeedUpdate) {
return;
}
// If update is required, open the authentication page through the URL.
Object urlValue = about.get("updateUrl");
String url = "";
if (urlValue instanceof String) {
url = (String) urlValue;
}
if (TextUtils.isEmpty(url)) {
return;
}
Uri uri = Uri.parse(url);
if (!"https".equals(uri.getScheme())) {
return;
}
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
try {
startActivity(intent);
} catch (ActivityNotFoundException e) {
Logger.e(TAG, "Activity not found");
}
}
The needUpdate field is optional, and the Drive.About.Get API may not return this field.