当前位置: 首页>>代码示例>>Java>>正文


Java Drive.getDriveClient方法代码示例

本文整理汇总了Java中com.google.android.gms.drive.Drive.getDriveClient方法的典型用法代码示例。如果您正苦于以下问题:Java Drive.getDriveClient方法的具体用法?Java Drive.getDriveClient怎么用?Java Drive.getDriveClient使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.android.gms.drive.Drive的用法示例。


在下文中一共展示了Drive.getDriveClient方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setupClient

import com.google.android.gms.drive.Drive; //导入方法依赖的package包/类
/**
 * Set up the Drive API client.
 *
 * @param prefs The SharedPreferences
 * @return Whether the setup was successful
 */
private boolean setupClient(@NonNull SharedPreferences prefs) {
    final GoogleSignInOptions signInOptions =
            new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
                    .requestScopes(Drive.SCOPE_APPFOLDER)
                    .build();
    final GoogleSignInClient signInClient = GoogleSignIn.getClient(mContext, signInOptions);
    try {
        final GoogleSignInAccount signInAccount = Tasks.await(signInClient.silentSignIn());

        mClient = Drive.getDriveClient(mContext, signInAccount);
        mResourceClient = Drive.getDriveResourceClient(mContext, signInAccount);

        Log.d(TAG, "Connection successful. sync: " + mShouldSync + " media: " + mMediaMounted);

        return true;
    } catch(ExecutionException e) {
        final ApiException result = (ApiException)e.getCause();
        switch(result.getStatusCode()) {
            case GoogleSignInStatusCodes.SIGN_IN_REQUIRED:
            case GoogleSignInStatusCodes.INVALID_ACCOUNT:
                Log.i(TAG, "User not signed in. Disabling photo syncing.");
                prefs.edit().putBoolean(FlavordexApp.PREF_SYNC_PHOTOS, false).apply();
                break;
            case GoogleSignInStatusCodes.API_NOT_CONNECTED:
            case GoogleSignInStatusCodes.NETWORK_ERROR:
            case GoogleSignInStatusCodes.INTERNAL_ERROR:
                Log.i(TAG, "Google Drive service unavailable. Disabling photo syncing.");
                prefs.edit().putBoolean(FlavordexApp.PREF_SYNC_PHOTOS, false).apply();
        }

        Log.w(TAG, "Connection failed! Reason: " + result.getMessage());
    } catch(InterruptedException ignored) {
    }

    return false;
}
 
开发者ID:ultramega,项目名称:flavordex,代码行数:43,代码来源:PhotoSyncHelper.java

示例2: loadDriveApiClients

import com.google.android.gms.drive.Drive; //导入方法依赖的package包/类
private boolean loadDriveApiClients() {
    Set<Scope> requiredScopes = new HashSet<>(2);
    requiredScopes.add(Drive.SCOPE_FILE);
    requiredScopes.add(Drive.SCOPE_APPFOLDER);

    GoogleSignInAccount signInAccount = GoogleSignIn.getLastSignedInAccount(this);
    if (signInAccount != null && signInAccount.getGrantedScopes().containsAll(requiredScopes)) {
        mDriveClient = Drive.getDriveClient(getApplicationContext(), signInAccount);
        mDriveResourceClient = Drive.getDriveResourceClient(getApplicationContext(), signInAccount);

        return true;
    }

    return false;
}
 
开发者ID:canyapan,项目名称:DietDiaryApp,代码行数:16,代码来源:DriveBackupService.java

示例3: initializeDriveClient

import com.google.android.gms.drive.Drive; //导入方法依赖的package包/类
private void initializeDriveClient(GoogleSignInAccount signInAccount) {
    mDriveClient = Drive.getDriveClient(getContext(), signInAccount);
    mDriveResourceClient = Drive.getDriveResourceClient(getContext(), signInAccount);

    onDriveClientReady();
}
 
开发者ID:canyapan,项目名称:DietDiaryApp,代码行数:7,代码来源:SettingsSupportFragment.java

示例4: initializeDriveClient

import com.google.android.gms.drive.Drive; //导入方法依赖的package包/类
/**
 * Continues the sign-in process, initializing the DriveResourceClient with the current
 * user's account.
 */
private void initializeDriveClient(GoogleSignInAccount signInAccount) {
    mDriveClient = Drive.getDriveClient(getApplicationContext(), signInAccount);
    mDriveResourceClient = Drive.getDriveResourceClient(getApplicationContext(), signInAccount);
    onDriveClientReady();
}
 
开发者ID:googledrive,项目名称:android-conflict,代码行数:10,代码来源:BaseDemoActivity.java


注:本文中的com.google.android.gms.drive.Drive.getDriveClient方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。