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


Java GoogleAuthUtil類代碼示例

本文整理匯總了Java中com.google.android.gms.auth.GoogleAuthUtil的典型用法代碼示例。如果您正苦於以下問題:Java GoogleAuthUtil類的具體用法?Java GoogleAuthUtil怎麽用?Java GoogleAuthUtil使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


GoogleAuthUtil類屬於com.google.android.gms.auth包,在下文中一共展示了GoogleAuthUtil類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getToken

import com.google.android.gms.auth.GoogleAuthUtil; //導入依賴的package包/類
private void getToken(Context context) {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    String email = sharedPreferences.getString(Constants.KEY_EMAIL, null);
    mUserGoogleId = sharedPreferences.getString(Constants.KEY_USER_GOOGLE_ID, null);
    mUserUID = sharedPreferences.getString(Constants.KEY_USER_UID, null); //firebase userId

    try {
        String scope = String.format("oauth2:%s", "https://picasaweb.google.com/data/");
        String token = null;
        if (email != null) {
            token = GoogleAuthUtil.getToken(context, email, scope);
        }

        Log.i(TAG, "Get Token\n" +
                "2 Picasa client " + mPicasaClient + "\n" +
                "2 Picasa service " + mPicasaService + "\n" +
                "--- Google token " + token);

        mPicasaClient.createService(token);
        mPicasaService = mPicasaClient.getPicasaService();
    } catch (IOException | GoogleAuthException e) {
        e.printStackTrace();
    }
}
 
開發者ID:trigor74,項目名稱:travelers-diary,代碼行數:25,代碼來源:SyncService.java

示例2: handleSignInResult

import com.google.android.gms.auth.GoogleAuthUtil; //導入依賴的package包/類
protected void handleSignInResult(GoogleSignInResult result) {
    Schedulers.newThread()
            .scheduleDirect(() -> {
                if (result.isSuccess()) {
                    if (result.getSignInAccount() != null && result.getSignInAccount().getAccount() != null) {
                        Account account = result.getSignInAccount().getAccount();
                        try {
                            String token = GoogleAuthUtil.getToken(activity, account, "oauth2:" + SCOPE_PICASA);
                            emitter.onSuccess(new GoogleSignIn.SignInAccount(token, result.getSignInAccount()));
                        } catch (IOException | GoogleAuthException e) {
                            emitter.onError(new SignInException("SignIn", e));
                        }
                    } else {
                        emitter.onError(new SignInException("SignIn", "getSignInAccount is null!", 0));
                    }

                } else {
                    if (result.getStatus().getStatusCode() == CommonStatusCodes.SIGN_IN_REQUIRED) {
                        emitter.onError(new SignInRequiredException());
                    } else {
                        emitter.onError(new SignInException("SignIn", result.getStatus().getStatusMessage(), result.getStatus().getStatusCode()));
                    }
                }
            });
}
 
開發者ID:yosriz,項目名稱:RxGooglePhotos,代碼行數:26,代碼來源:GoogleSignInOnSubscribeBase.java

示例3: onAuthSuccess

import com.google.android.gms.auth.GoogleAuthUtil; //導入依賴的package包/類
/**
 * Called when authentication succeeds. This may either happen because the user just
 * authenticated for the first time (and went through the sign in flow), or because it's
 * a returning user.
 *
 * @param accountName        name of the account that just authenticated successfully.
 * @param newlyAuthenticated If true, this user just authenticated for the first time.
 *                           If false, it's a returning user.
 */
@Override
public void onAuthSuccess(String accountName, boolean newlyAuthenticated) {
    Account account = new Account(accountName, GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE);
    LOGD(TAG, "onAuthSuccess, account " + accountName + ", newlyAuthenticated="
            + newlyAuthenticated);

    refreshAccountDependantData();

    if (newlyAuthenticated) {
        LOGD(TAG, "Enabling auto sync on content provider for account " + accountName);
        SyncHelper.updateSyncInterval(this, account);
        SyncHelper.requestManualSync(account);
    }

    setupAccountBox();
    populateNavDrawer();
    registerGCMClient();
}
 
開發者ID:dreaminglion,項目名稱:iosched-reader,代碼行數:28,代碼來源:BaseActivity.java

示例4: onStatusChanged

import com.google.android.gms.auth.GoogleAuthUtil; //導入依賴的package包/類
@Override
public void onStatusChanged(int which) {
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            String accountName = AccountUtils.getActiveAccountName(BaseActivity.this);
            if (TextUtils.isEmpty(accountName)) {
                onRefreshingStateChanged(false);
                mManualSyncRequest = false;
                return;
            }

            Account account = new Account(accountName, GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE);
            boolean syncActive = ContentResolver.isSyncActive(
                    account, ScheduleContract.CONTENT_AUTHORITY);
            boolean syncPending = ContentResolver.isSyncPending(
                    account, ScheduleContract.CONTENT_AUTHORITY);
            if (!syncActive && !syncPending) {
                mManualSyncRequest = false;
            }
            onRefreshingStateChanged(syncActive || mManualSyncRequest);
        }
    });
}
 
開發者ID:dreaminglion,項目名稱:iosched-reader,代碼行數:25,代碼來源:BaseActivity.java

示例5: getAccountType

import com.google.android.gms.auth.GoogleAuthUtil; //導入依賴的package包/類
/**
 * Get the account type associated with the install location of the app
 *
 * @return the account type
 */
public static String getAccountType() {
    if (DEBUG) {
        MyLog.i(CLS_NAME, "getAccountType");
    }

    switch (Global.installLocation) {

        case PLAYSTORE:
            if (DEBUG) {
                MyLog.i(CLS_NAME, "getAccountType PLAYSTORE");
            }
            return GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE;
        case AMAZON:
            if (DEBUG) {
                MyLog.i(CLS_NAME, "getAccountType AMAZON");
            }
            return "";
        default:
            return "";
    }
}
 
開發者ID:brandall76,項目名稱:Saiy-PS,代碼行數:27,代碼來源:Install.java

示例6: getAccount

import com.google.android.gms.auth.GoogleAuthUtil; //導入依賴的package包/類
private static Account getAccount() throws MissingGoogleAccountException, PermissionsException {
    String accountName = Settings.getGoogleAccountName();

    if (ContextCompat.checkSelfPermission(GlobalApplication.getAppContext(), Manifest.permission.GET_ACCOUNTS) != PackageManager.PERMISSION_GRANTED) {
        throw new PermissionsException(Manifest.permission.GET_ACCOUNTS);
    } else {

        AccountManager manager = AccountManager.get(GlobalApplication.getAppContext());
        Account[] accounts = manager.getAccountsByType(GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE);

        for (Account acc: accounts) {
            if (acc.name.equals(accountName)) {
                return acc;
            }
        }

        throw new MissingGoogleAccountException("GoogleAccountsService");

    }
}
 
開發者ID:timothymiko,項目名稱:narrate-android,代碼行數:21,代碼來源:GoogleAccountsService.java

示例7: signInOrCreateAnAccount

import com.google.android.gms.auth.GoogleAuthUtil; //導入依賴的package包/類
private void signInOrCreateAnAccount() {
    //Get list of accounts on device.
    AccountManager am = AccountManager.get(BaseActivity.this);
    Account[] accountArray = am.getAccountsByType(GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE);
    if (accountArray.length == 0) {
        //Send the user to the "Add Account" page.
        Intent intent = new Intent(Settings.ACTION_ADD_ACCOUNT);
        intent.putExtra(Settings.EXTRA_ACCOUNT_TYPES,
                new String[]{GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE});
        startActivity(intent);
    } else {
        //Try to log the user in with the first account on the device.
        startLoginProcess();
        mDrawerLayout.closeDrawer(GravityCompat.START);
    }
}
 
開發者ID:silicon-mountain,項目名稱:smconf-android,代碼行數:17,代碼來源:BaseActivity.java

示例8: authenticate

import com.google.android.gms.auth.GoogleAuthUtil; //導入依賴的package包/類
@Override
public Request authenticate(Route route, Response response) throws IOException {
    Log.d(TAG, "Re-authenticating requests");
    if (responseCount(response) >= 3) {
        return null; // If we've failed 3 times, give up. - in real life, never give up!!
    } else {
        try {
            if (mContext == null)
                Log.d(TAG, "Context is null");
            String token = GoogleAuthUtil.getToken(mContext, Utils.getLoginEmail(mContext), Constants.URL_SHORTNER_SCOPE);
            Log.d(TAG, "New token is " + token);
            Utils.setAuthToken(mContext, token);
            return response.request().newBuilder()
                    .header("Authorization", "Bearer " + Utils.getAuthToken(mContext))
                    .build();
        } catch (GoogleAuthException e) {
            e.printStackTrace();
            return null;
        }

    }


}
 
開發者ID:jatindhankhar,項目名稱:shorl,代碼行數:25,代碼來源:TokenAuthenticator.java

示例9: authenticate

import com.google.android.gms.auth.GoogleAuthUtil; //導入依賴的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

示例10: fetchToken

import com.google.android.gms.auth.GoogleAuthUtil; //導入依賴的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

示例11: getUserProfileOnGingerbreadDevice

import com.google.android.gms.auth.GoogleAuthUtil; //導入依賴的package包/類
/**
 * Retrieves the user profile information in a manner supported by
 * Gingerbread devices.
 *
 * @param context the context from which to retrieve the user's email address
 *                and name
 * @return a list of the possible user's email address and name
 */
private static UserProfile getUserProfileOnGingerbreadDevice(Context context)
{
    // Other that using Patterns (API level 8) this works on devices down to
    // API level 5
    final Matcher valid_email_address = Patterns.EMAIL_ADDRESS.matcher("");
    final Account[] accounts = AccountManager.get(context).getAccountsByType(GoogleAuthUtil
            .GOOGLE_ACCOUNT_TYPE);
    UserProfile user_profile = new UserProfile();
    // As far as I can tell, there is no way to get the real name or phone
    // number from the Google account
    for(Account account : accounts)
    {
        if(valid_email_address.reset(account.name).matches())
            user_profile.addPossibleEmail(account.name);
    }
    // Gets the phone number of the device is the device has one
    if(context.getPackageManager().hasSystemFeature(Context.TELEPHONY_SERVICE))
    {
        final TelephonyManager telephony = (TelephonyManager) context.getSystemService
                (Context.TELEPHONY_SERVICE);
        user_profile.addPossiblePhoneNumber(telephony.getLine1Number());
    }

    return user_profile;
}
 
開發者ID:GNUDimarik,項目名稱:evercam-play-android2,代碼行數:34,代碼來源:AccountUtils.java

示例12: onAuthSuccess

import com.google.android.gms.auth.GoogleAuthUtil; //導入依賴的package包/類
/**
 * Called when authentication succeeds. This may either happen because the user just
 * authenticated for the first time (and went through the sign in flow), or because it's
 * a returning user.
 * @param accountName name of the account that just authenticated successfully.
 * @param newlyAuthenticated If true, this user just authenticated for the first time.
 * If false, it's a returning user.
 */
@Override
public void onAuthSuccess(String accountName, boolean newlyAuthenticated) {
    Account account = new Account(accountName, GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE);
    LogUtils.LOGD(TAG, "onAuthSuccess, account " + accountName + ", newlyAuthenticated=" + newlyAuthenticated);

    refreshAccountDependantData();

    if (newlyAuthenticated) {
        LogUtils.LOGD(TAG, "Enabling auto sync on content provider for account " + accountName);
        SyncHelper.updateSyncInterval(this, account);
        SyncHelper.requestManualSync(account);
    }

    setupAccountBox();
    populateNavDrawer();
    registerGCMClient();
}
 
開發者ID:The-WebOps-Club,項目名稱:saarang-iosched,代碼行數:26,代碼來源:BaseActivity.java

示例13: onStatusChanged

import com.google.android.gms.auth.GoogleAuthUtil; //導入依賴的package包/類
@Override
public void onStatusChanged(int which) {
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            String accountName = AccountUtils.getActiveAccountName(BaseActivity.this);
            if (TextUtils.isEmpty(accountName)) {
                onRefreshingStateChanged(false);
                mManualSyncRequest = false;
                return;
            }

            Account account = new Account(accountName, GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE);
            boolean syncActive = ContentResolver.isSyncActive(
                    account, ScheduleContract.CONTENT_AUTHORITY);
            boolean syncPending = ContentResolver.isSyncPending(
                    account, ScheduleContract.CONTENT_AUTHORITY);
            if (!syncActive && !syncPending) {
                mManualSyncRequest = false;
            }
            onRefreshingStateChanged(syncActive || (mManualSyncRequest && syncPending));
        }
    });
}
 
開發者ID:The-WebOps-Club,項目名稱:saarang-iosched,代碼行數:25,代碼來源:BaseActivity.java

示例14: onAuthSuccess

import com.google.android.gms.auth.GoogleAuthUtil; //導入依賴的package包/類
/**
 * Called when authentication succeeds. This may either happen because the user just
 * authenticated for the first time (and went through the sign in flow), or because it's
 * a returning user.
 * @param accountName name of the account that just authenticated successfully.
 * @param newlyAuthenticated If true, this user just authenticated for the first time.
 * If false, it's a returning user.
 */
@Override
public void onAuthSuccess(String accountName, boolean newlyAuthenticated) {
    Account account = new Account(accountName, GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE);
    LOGD(TAG, "onAuthSuccess, account " + accountName + ", newlyAuthenticated=" + newlyAuthenticated);

    refreshAccountDependantData();

    if (newlyAuthenticated) {
        LOGD(TAG, "Enabling auto sync on content provider for account " + accountName);
        SyncHelper.updateSyncInterval(this, account);
        SyncHelper.requestManualSync(account);
    }

    setupAccountBox();
    populateNavDrawer();
    registerGCMClient();
}
 
開發者ID:gdg-bh,項目名稱:AppDevFestSudeste2015,代碼行數:26,代碼來源:BaseActivity.java

示例15: onStatusChanged

import com.google.android.gms.auth.GoogleAuthUtil; //導入依賴的package包/類
@Override
public void onStatusChanged(int which) {
    if (mActivity != null) {
        mActivity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if (mActivity == null) {
                    return;
                }
                String accountName = AccountUtils.getActiveAccountName(mActivity);
                if (TextUtils.isEmpty(accountName)) {
                    mActivity.onRefreshingStateChanged(false);
                    return;
                }
                android.accounts.Account account = new android.accounts.Account(
                        accountName, GoogleAuthUtil.GOOGLE_ACCOUNT_TYPE);
                boolean syncActive = ContentResolver.isSyncActive(
                        account, ScheduleContract.CONTENT_AUTHORITY);
                mActivity.onRefreshingStateChanged(syncActive);
            }
        });
    }
}
 
開發者ID:google,項目名稱:iosched,代碼行數:24,代碼來源:BaseActivity.java


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