本文整理匯總了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();
}