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


Java UserRecoverableAuthException類代碼示例

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

示例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;
    }
 
開發者ID:timothymiko,項目名稱:narrate-android,代碼行數:22,代碼來源:SyncHelper.java

示例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;
}
 
開發者ID:Last-Mile-Health,項目名稱:ODK-Liberia,代碼行數:17,代碼來源:GoogleMapsEngineTask.java

示例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;
        }
 
開發者ID:NaikSoftware,項目名稱:NaikSoftware-Lib-Android,代碼行數:23,代碼來源:GoogleAuthProvider.java

示例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);
}
 
開發者ID:labhackercd,項目名稱:edm,代碼行數:20,代碼來源:AddMessageTask.java

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

示例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);
            }
        }
    });
}
 
開發者ID:TerribleDev,項目名稱:XamarinAdmobTutorial,代碼行數:30,代碼來源:HelloActivity.java

示例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;
}
 
開發者ID:oalami,項目名稱:slidee-android,代碼行數:24,代碼來源:FirebaseService.java

示例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;
}
 
開發者ID:DarrenMowat,項目名稱:PicSync,代碼行數:23,代碼來源:GetTokenTask.java

示例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();
}
 
開發者ID:DarrenMowat,項目名稱:PicSync,代碼行數:21,代碼來源:MediaService.java

示例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();
}
 
開發者ID:DarrenMowat,項目名稱:PicSync,代碼行數:23,代碼來源:UploadService.java

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

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

示例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


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