目录

Obtaining User Information

Use Cases

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.

Prerequisites

1. You have made all necessary preparations.

2. You have downloaded the client sample code and tried it out.

Creating a Drive Object

Call the Drive.Builder.build API to create a Drive object.
private Drive buildDrive() {  
    Drive service = new Drive.Builder(CredentialManager.getInstance().getCredential(), context).build();  
    return service;  
}

Obtaining User Information

Call the Drive.About.Get API to obtain user information. setFields("*") indicates that all fields need to be returned.
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.

Updating the Security Policy

Check the value of needUpdate in the response returned by the Drive.About.Get API. If it is true, the user's security policy needs to be updated. In this case, your app jumps to the authorization page based on the returned address and continues to provide services after obtaining authorization from the user.
/**   
 * 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.