当前位置: 首页>>代码示例>>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;未经允许,请勿转载。