本文整理汇总了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;
}
示例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;
}
示例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();
}
示例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();
}