本文整理匯總了Java中com.google.android.gms.auth.UserRecoverableAuthException.getIntent方法的典型用法代碼示例。如果您正苦於以下問題:Java UserRecoverableAuthException.getIntent方法的具體用法?Java UserRecoverableAuthException.getIntent怎麽用?Java UserRecoverableAuthException.getIntent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.android.gms.auth.UserRecoverableAuthException
的用法示例。
在下文中一共展示了UserRecoverableAuthException.getIntent方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: create
import com.google.android.gms.auth.UserRecoverableAuthException; //導入方法依賴的package包/類
public static Drive create(Context context, String googleDriveAccount) throws IOException, GoogleAuthException, ImportExportException {
if (googleDriveAccount == null) {
throw new ImportExportException(R.string.google_drive_account_required);
}
try {
List<String> scope = new ArrayList<String>();
scope.add(DriveScopes.DRIVE_FILE);
if (MyPreferences.isGoogleDriveFullReadonly(context)) {
scope.add(DriveScopes.DRIVE_READONLY);
}
GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(context, scope);
credential.setSelectedAccountName(googleDriveAccount);
credential.getToken();
return new Drive.Builder(AndroidHttp.newCompatibleTransport(), new GsonFactory(), credential).build();
} catch (UserRecoverableAuthException e) {
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Intent authorizationIntent = e.getIntent();
authorizationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).addFlags(
Intent.FLAG_FROM_BACKGROUND);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
authorizationIntent, 0);
Notification notification = new NotificationCompat.Builder(context)
.setSmallIcon(android.R.drawable.ic_dialog_alert)
.setTicker(context.getString(R.string.google_drive_permission_requested))
.setContentTitle(context.getString(R.string.google_drive_permission_requested))
.setContentText(context.getString(R.string.google_drive_permission_requested_for_account, googleDriveAccount))
.setContentIntent(pendingIntent).setAutoCancel(true).build();
notificationManager.notify(0, notification);
throw new ImportExportException(R.string.google_drive_permission_required);
}
}
示例2: create
import com.google.android.gms.auth.UserRecoverableAuthException; //導入方法依賴的package包/類
public static Drive create(Context context) throws IOException, GoogleAuthException, ImportExportException {
String googleDriveAccount = MyPreferences.getGoogleDriveAccount(context);
if (googleDriveAccount == null) {
throw new ImportExportException(R.string.google_drive_account_required);
}
try {
List<String> scope = new ArrayList<String>();
scope.add(DriveScopes.DRIVE_FILE);
if (MyPreferences.isGoogleDriveFullReadonly(context)) {
scope.add(DriveScopes.DRIVE_READONLY);
}
GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(context, scope);
credential.setSelectedAccountName(googleDriveAccount);
credential.getToken();
return new Drive.Builder(AndroidHttp.newCompatibleTransport(), new GsonFactory(), credential).build();
} catch (UserRecoverableAuthException e) {
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Intent authorizationIntent = e.getIntent();
authorizationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).addFlags(
Intent.FLAG_FROM_BACKGROUND);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
authorizationIntent, 0);
Notification notification = new NotificationCompat.Builder(context)
.setSmallIcon(android.R.drawable.ic_dialog_alert)
.setTicker(context.getString(R.string.google_drive_permission_requested))
.setContentTitle(context.getString(R.string.google_drive_permission_requested))
.setContentText(context.getString(R.string.google_drive_permission_requested_for_account, googleDriveAccount))
.setContentIntent(pendingIntent).setAutoCancel(true).build();
notificationManager.notify(0, notification);
throw new ImportExportException(R.string.google_drive_permission_required);
}
}
示例3: create
import com.google.android.gms.auth.UserRecoverableAuthException; //導入方法依賴的package包/類
public static Drive create(Context context, String googleDriveAccount) throws IOException, GoogleAuthException, ImportExportException {
if (googleDriveAccount == null) {
throw new ImportExportException(R.string.google_drive_account_select_error);
}
try {
List<String> scope = new ArrayList<String>();
scope.add(DriveScopes.DRIVE_FILE);
if (MyPreferences.isGoogleDriveFullReadonly(context)) {
scope.add(DriveScopes.DRIVE_READONLY);
}
GoogleAccountCredential credential = GoogleAccountCredential.usingOAuth2(context, scope);
credential.setSelectedAccountName(googleDriveAccount);
credential.getToken();
return new Drive.Builder(AndroidHttp.newCompatibleTransport(), new GsonFactory(), credential).build();
} catch (UserRecoverableAuthException e) {
NotificationManager notificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
Intent authorizationIntent = e.getIntent();
authorizationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).addFlags(
Intent.FLAG_FROM_BACKGROUND);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
authorizationIntent, 0);
Notification notification = new NotificationCompat.Builder(context)
.setSmallIcon(android.R.drawable.ic_dialog_alert)
.setTicker(context.getString(R.string.google_drive_permission_requested))
.setContentTitle(context.getString(R.string.google_drive_permission_requested))
.setContentText(context.getString(R.string.google_drive_permission_requested_for_account) +" " + googleDriveAccount)
.setContentIntent(pendingIntent).setAutoCancel(true).build();
notificationManager.notify(0, notification);
throw new ImportExportException(R.string.google_drive_permission_required);
}
}
示例4: handleException
import com.google.android.gms.auth.UserRecoverableAuthException; //導入方法依賴的package包/類
protected void handleException(UserRecoverableAuthException e) {
// Unable to authenticate, such as when the user has not yet granted
// the app access to the account, but the user can fix this.
// Forward the user to an activity in Google Play services.
Intent intent = e.getIntent();
startActivityForResult(intent,
REQUEST_CODE_RECOVER_FROM_PLAY_SERVICES_ERROR);
}
示例5: doInBackground
import com.google.android.gms.auth.UserRecoverableAuthException; //導入方法依賴的package包/類
@Override
protected Boolean doInBackground(Object... unused) {
Log.i(LOG_TAG, "Background task started.");
// Ensure only one task is running at a time.
mAuthTask = this;
// Ensure an email was selected.
String emailAccount = LoginActivity.this.getEmailAccount();
if (Strings.isNullOrEmpty(emailAccount)) {
publishProgress(R.string.toast_no_google_account_selected);
// Failure.
return false;
}
String oauth2 = AppUtils.getOAuth2ScopeString(new String[]{ComputeScopes.COMPUTE,
ComputeScopes.DEVSTORAGE_READ_ONLY});
if (DEBUG) {
Log.d(LOG_TAG, "Attempting to get AuthToken for account: " + getEmailAccount());
}
try {
// If the application has the appropriate access then a token will be retrieved, otherwise
// an error will be thrown.
GoogleAuthUtil.getToken(LoginActivity.this, getEmailAccount(), oauth2, null);
if (DEBUG) {
Log.d(LOG_TAG, "AuthToken retrieved");
}
// Success.
return true;
} catch (UserRecoverableAuthException userRecoverableException) {
Log.w(LOG_TAG, "User recoverable auth exception; firing intent to resolve.",
userRecoverableException);
// Invoke the embedded intent to allow the user to resolve the issue causing the exception.
// The intent is typically the acceptance of an OAuth2 authorization screen for the app.
userRecoverableIntent = userRecoverableException.getIntent();
return false;
} catch (GoogleAuthException authException) {
Log.e(LOG_TAG, "Exception checking OAuth2 authentication.", authException);
publishProgress(R.string.toast_exception_checking_authorization);
return false;
} catch (IOException ioException) {
Log.e(LOG_TAG, "Exception checking OAuth2 authentication.", ioException);
publishProgress(R.string.toast_exception_checking_authorization);
return false;
}
}