當前位置: 首頁>>代碼示例>>Java>>正文


Java UserRecoverableAuthException.getIntent方法代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:tiberiusteng,項目名稱:financisto1-holo,代碼行數:33,代碼來源:GoogleDriveClient.java

示例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);
    }
}
 
開發者ID:tiberiusteng,項目名稱:financisto1-holo,代碼行數:34,代碼來源:GoogleDrivePictureClient.java

示例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);
    }
}
 
開發者ID:emmanuel-florent,項目名稱:flowzr-android-black,代碼行數:33,代碼來源:GoogleDriveClient.java

示例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);
}
 
開發者ID:sschendel,項目名稱:SyncManagerAndroid-DemoGoogleTasks,代碼行數:9,代碼來源:MainActivity.java

示例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;
  }
}
 
開發者ID:googlearchive,項目名稱:compute-getting-started-android,代碼行數:51,代碼來源:LoginActivity.java


注:本文中的com.google.android.gms.auth.UserRecoverableAuthException.getIntent方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。