本文整理汇总了Java中com.google.android.gms.auth.UserRecoverableAuthException类的典型用法代码示例。如果您正苦于以下问题:Java UserRecoverableAuthException类的具体用法?Java UserRecoverableAuthException怎么用?Java UserRecoverableAuthException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UserRecoverableAuthException类属于com.google.android.gms.auth包,在下文中一共展示了UserRecoverableAuthException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleAuthException
import com.google.android.gms.auth.UserRecoverableAuthException; //导入依赖的package包/类
private void handleAuthException(final Activity activity, final Exception e) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
if (e instanceof GooglePlayServicesAvailabilityException) {
// The Google Play services APK is old, disabled, or not present.
// Show a dialog created by Google Play services that allows
// the user to update the APK
int statusCode = ((GooglePlayServicesAvailabilityException) e).getConnectionStatusCode();
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(
statusCode, activity, REQUEST_CODE_RECOVER_FROM_PLAY_SERVICES_ERROR_FOR_URL_SHORTNER);
dialog.show();
} else if (e instanceof UserRecoverableAuthException) {
// 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 = ((UserRecoverableAuthException) e).getIntent();
activity.startActivityForResult(
intent, REQUEST_CODE_RECOVER_FROM_PLAY_SERVICES_ERROR_FOR_URL_SHORTNER);
}
}
});
}
开发者ID:NordicSemiconductor,项目名称:Android-nRF-Beacon-for-Eddystone,代码行数:25,代码来源:AuthTaskUrlShortener.java
示例2: handleAuthException
import com.google.android.gms.auth.UserRecoverableAuthException; //导入依赖的package包/类
public static void handleAuthException(final Activity activity, final Exception e) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
if (e instanceof GooglePlayServicesAvailabilityException) {
// The Google Play services APK is old, disabled, or not present.
// Show a dialog created by Google Play services that allows
// the user to update the APK
int statusCode = ((GooglePlayServicesAvailabilityException)e).getConnectionStatusCode();
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(
statusCode, activity, Constants.REQUEST_CODE_RECOVER_FROM_PLAY_SERVICES_ERROR);
dialog.show();
}
else if (e instanceof UserRecoverableAuthException) {
// 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 = ((UserRecoverableAuthException)e).getIntent();
activity.startActivityForResult(
intent, Constants.REQUEST_CODE_RECOVER_FROM_PLAY_SERVICES_ERROR);
}
}
});
}
示例3: getSyncServices
import com.google.android.gms.auth.UserRecoverableAuthException; //导入依赖的package包/类
public static List<AbsSyncService> getSyncServices() {
List<AbsSyncService> syncServices = new ArrayList<>();
if (Settings.getDropboxSyncEnabled())
syncServices.add(new DropboxSyncService());
if (Settings.getGoogleDriveSyncEnabled()) {
try {
DriveSyncService syncService = new DriveSyncService();
syncServices.add(syncService);
} catch (UserRecoverableAuthException e) {
e.printStackTrace();
Settings.setGoogleDriveSyncEnabled(false);
Toast.makeText(GlobalApplication.getAppContext(), "Google Drive Error. Disabling Drive sync for now.", Toast.LENGTH_LONG).show();
}
}
return syncServices;
}
示例4: authenticate
import com.google.android.gms.auth.UserRecoverableAuthException; //导入依赖的package包/类
protected String authenticate(Context context, String mGoogleUserName)
throws IOException, GoogleAuthException,
GooglePlayServicesAvailabilityException,
UserRecoverableAuthException {
// use google auth utils to get oauth2 token
String scope = "oauth2:https://www.googleapis.com/auth/mapsengine https://picasaweb.google.com/data/";
String token = null;
if (mGoogleUserName == null) {
Log.e(tag, "Google user not set");
return null;
}
token = GoogleAuthUtil.getToken(context, mGoogleUserName, scope);
return token;
}
示例5: fetchToken
import com.google.android.gms.auth.UserRecoverableAuthException; //导入依赖的package包/类
/**
* Gets an authentication token from Google and handles any
* GoogleAuthException that may occur.
*/
protected String fetchToken() throws IOException {
try {
return GoogleAuthUtil.getToken(mActivity, mEmail, mScope);
} catch (UserRecoverableAuthException userRecoverableException) {
// GooglePlayServices.apk is either old, disabled, or not present
// so we need to show the user some UI in the activity to recover.
handleException(userRecoverableException);
} catch (GoogleAuthException fatalException) {
// Some other type of unrecoverable exception has occurred.
// Report and log the error as appropriate for your app.
// LogHelper.LOGD("GoogleAuthProvider","GetUserNameTask: " + fatalException.getMessage());
// Toast.makeText(mActivity, fatalException.getMessage(), Toast.LENGTH_SHORT).show();
if (getAuthCallback() != null) {
getAuthCallback().onError(fatalException);
}
}
return null;
}
示例6: onError
import com.google.android.gms.auth.UserRecoverableAuthException; //导入依赖的package包/类
public void onError(Throwable error) {
LocalMessage.Status status = LocalMessage.Status.CANCEL;
// YEAH :D
while (error instanceof UserRecoverableAuthIOException) {
error = ((UserRecoverableAuthIOException) error).getCause();
}
if (error instanceof UserRecoverableAuthException) {
status = LocalMessage.Status.CANCEL_RECOVERABLE_AUTH_ERROR;
MainActivity.notifyUserRecoverableAuthException(
application, message, (UserRecoverableAuthException) error);
} else {
Timber.e(error, "Message submission failed.");
notifyError(error);
}
messages.setStatus(message.getId(), status);
}
示例7: fetchToken
import com.google.android.gms.auth.UserRecoverableAuthException; //导入依赖的package包/类
/**
* Gets an authentication token from Google and handles any
* GoogleAuthException that may occur.
*/
protected String fetchToken() throws IOException {
try {
return GoogleAuthUtil.getToken(MainActivity.this, mEmailText, mScope);
} catch (UserRecoverableAuthException userRecoverableException) {
// GooglePlayServices.apk is either old, disabled, or not present
// so we need to show the user some UI in the activity to recover.
//mActivity.handleException(userRecoverableException);
//Log.e(TAG, userRecoverableException.getMessage(), userRecoverableException);
mException = userRecoverableException;
} catch (GoogleAuthException fatalException) {
// Some other type of unrecoverable exception has occurred.
// Report and log the error as appropriate for your app.
Log.e(TAG, fatalException.getMessage(), fatalException);
}
return null;
}
示例8: handleException
import com.google.android.gms.auth.UserRecoverableAuthException; //导入依赖的package包/类
/**
* This method is a hook for background threads and async tasks that need to provide the
* user a response UI when an exception occurs.
*/
public void handleException(final Exception e) {
runOnUiThread(new Runnable() {
@Override
public void run() {
if (e instanceof GooglePlayServicesAvailabilityException) {
// The Google Play services APK is old, disabled, or not present.
// Show a dialog created by Google Play services that allows
// the user to update the APK
int statusCode = ((GooglePlayServicesAvailabilityException)e)
.getConnectionStatusCode();
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(statusCode,
HelloActivity.this,
REQUEST_CODE_RECOVER_FROM_PLAY_SERVICES_ERROR);
dialog.show();
} else if (e instanceof UserRecoverableAuthException) {
// 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 = ((UserRecoverableAuthException)e).getIntent();
startActivityForResult(intent,
REQUEST_CODE_RECOVER_FROM_PLAY_SERVICES_ERROR);
}
}
});
}
示例9: fetchToken
import com.google.android.gms.auth.UserRecoverableAuthException; //导入依赖的package包/类
/**
* Fetches an access token from the G+ API
* @return the access token
* @throws IOException
*/
protected String fetchToken() throws IOException {
try {
return GoogleAuthUtil.getToken(
mContext,
Plus.AccountApi.getAccountName(mGoogleApiClient),
"oauth2:" + SCOPES);
} catch (UserRecoverableAuthException userRecoverableException) {
// GooglePlayServices.apk is either old, disabled, or not present
// so we need to show the user some UI in the activity to recover.
Log.e(TAG, userRecoverableException.toString());
} catch (GoogleAuthException fatalException) {
// Some other type of unrecoverable exception has occurred.
// Report and log the error as appropriate for your app.
Log.e(TAG, fatalException.toString());
}
return null;
}
示例10: fetchToken
import com.google.android.gms.auth.UserRecoverableAuthException; //导入依赖的package包/类
/**
* Get a authentication token if one is not available. If the error is not
* recoverable then it displays the error message on parent activity.
*/
private String fetchToken() {
try {
String token = GoogleAuthUtil.getToken(mActivity, mEmail, mScope);
return token;
} catch (GooglePlayServicesAvailabilityException playEx) {
// GooglePlayServices.apk is either old, disabled, or not present.
mActivity.showErrorDialog(playEx.getConnectionStatusCode());
} catch (UserRecoverableAuthException userRecoverableException) {
// Unable to authenticate, but the user can fix this.
// Forward the user to the appropriate activity.
mActivity.startActivityForResult(userRecoverableException.getIntent(), mRequestCode);
} catch (GoogleAuthException fatalException) {
mActivity.showErrorDialog(ConnectionResult.INTERNAL_ERROR);
} catch (IOException e) {
mActivity.showErrorDialog(ConnectionResult.NETWORK_ERROR);
}
return null;
}
示例11: onThreadError
import com.google.android.gms.auth.UserRecoverableAuthException; //导入依赖的package包/类
@Override
public void onThreadError(Exception e) {
thread = null;
if (e instanceof UserRecoverableAuthException) {
UserRecoverableAuthException userException = (UserRecoverableAuthException) e;
Notifier.notifyAuthError(MediaService.this, email, userException.getIntent());
} else {
e.printStackTrace();
String title = getResources().getString(
R.string.pref_title_upload_status_uploads_pending);
String msg = getResources().getString(
R.string.pref_summary_upload_status_uploads_failed);
DataBus.getInstance().post(new UploadStatusEvent(title, msg));
}
if (wakelock != null && wakelock.isHeld()) {
wakelock.release();
}
stopSelf();
}
示例12: onThreadError
import com.google.android.gms.auth.UserRecoverableAuthException; //导入依赖的package包/类
@Override
public void onThreadError(Exception e) {
log("UploadService crashed");
e.printStackTrace();
thread = null;
if (e instanceof UserRecoverableAuthException) {
UserRecoverableAuthException userException = (UserRecoverableAuthException) e;
Notifier.notifyAuthError(UploadService.this, email, userException.getIntent());
} else {
e.printStackTrace();
String title = getResources().getString(
R.string.pref_title_upload_status_uploads_pending);
String msg = getResources().getString(
R.string.pref_summary_upload_status_uploads_failed);
DataBus.getInstance().post(new UploadStatusEvent(title, msg));
}
if (wakelock != null && wakelock.isHeld()) {
wakelock.release();
}
stopSelf();
}
示例13: 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);
}
}
示例14: 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);
}
}
示例15: handleAuthException
import com.google.android.gms.auth.UserRecoverableAuthException; //导入依赖的package包/类
private void handleAuthException(final Activity activity, final Exception e) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
if (e instanceof GooglePlayServicesAvailabilityException) {
// The Google Play services APK is old, disabled, or not present.
// Show a dialog created by Google Play services that allows
// the user to update the APK
int statusCode = ((GooglePlayServicesAvailabilityException) e).getConnectionStatusCode();
Dialog dialog;
if(authScope.equals(AUTH_PROXIMITY_API)) {
dialog = GooglePlayServicesUtil.getErrorDialog(
statusCode, activity, REQUEST_CODE_RECOVER_FROM_PLAY_SERVICES_ERROR_FOR_PRX_API);
} else {
dialog = GooglePlayServicesUtil.getErrorDialog(
statusCode, activity, REQUEST_CODE_RECOVER_FROM_PLAY_SERVICES_ERROR_FOR_URL_SHORTNER);
}
dialog.show();
} else if (e instanceof UserRecoverableAuthException) {
// 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 = ((UserRecoverableAuthException) e).getIntent();
if(authScope.equals(AUTH_PROXIMITY_API)) {
activity.startActivityForResult(
intent, REQUEST_CODE_RECOVER_FROM_PLAY_SERVICES_ERROR_FOR_PRX_API);
} else {
activity.startActivityForResult(
intent, REQUEST_CODE_RECOVER_FROM_PLAY_SERVICES_ERROR_FOR_URL_SHORTNER);
}
}
}
});
}
开发者ID:NordicSemiconductor,项目名称:Android-nRF-Beacon-for-Eddystone,代码行数:35,代码来源:AuthorizedServiceTask.java