本文整理匯總了Java中com.google.android.gms.common.Scopes.EMAIL屬性的典型用法代碼示例。如果您正苦於以下問題:Java Scopes.EMAIL屬性的具體用法?Java Scopes.EMAIL怎麽用?Java Scopes.EMAIL使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類com.google.android.gms.common.Scopes
的用法示例。
在下文中一共展示了Scopes.EMAIL屬性的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: rxAction
@Override
public void rxAction(int requestCode) {
Assert.assertEquals(requestCode, ActivityResponses.GET_LOGINTOKEN);
final Activity activity = (Activity) getContext();
final String[] permissions = new String[]{Manifest.permission.GET_ACCOUNTS};
final Scope[] scopes = {new Scope(Scopes.PROFILE), new Scope(Scopes.EMAIL)};
// NB : Rationale is optional and can be null
final SnackbarRationaleOperator rationaleOperator = new SnackbarRationaleOperator(this, "Need permission for ...");
getLoginToken(activity, permissions, scopes, rationaleOperator)
.subscribe(new Consumer<String>() {
@Override
public void accept(String s) {
Toast.makeText(getContext(), "Token is : " + s, Toast.LENGTH_SHORT).show();
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) {
Toast.makeText(getContext(), "Exception : " + throwable, Toast.LENGTH_SHORT).show();
}
});
}
示例2: onConnected
/**
* Code borrowed from Google's Login sample with customization.
*/
@Override
public void onConnected(Bundle bundle) {
mShouldResolve = false;
// Once the connection to Google's API is successful, launch a new task to retrieve the
// access token from Google. Currently, the scope only covers the email in order to minimize
// the privilege
AsyncTask task = new AsyncTask() {
@Override
protected Object doInBackground(Object... params) {
String scope = "oauth2:" + Scopes.EMAIL;
try {
String email = Plus.AccountApi.getAccountName(mGoogleApiClient);
loginToken.setToken(GoogleAuthUtil.getToken(SelectDomain.this, email, scope));
loginToken.setLoginStatus(true);
// User can switch account next time when he wants to login
Plus.AccountApi.clearDefaultAccount(mGoogleApiClient);
mGoogleApiClient.disconnect();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* After login, we need to update the main UI
*/
@Override
protected void onPostExecute(Object o) {
super.onPostExecute(o);
updateUI();
}
};
task.execute((Void) null);
}
示例3: shouldSetScopes
@Test
public void shouldSetScopes() throws Exception {
Scope scope1 = new Scope(Scopes.PLUS_LOGIN);
Scope scope2 = new Scope(Scopes.EMAIL);
Scope scope3 = new Scope(Scopes.PROFILE);
provider.setScopes(scope1, scope2, scope3);
assertThat(provider.getScopes(), is(arrayWithSize(3)));
assertThat(provider.getScopes(), IsArrayContaining.hasItemInArray(scope1));
assertThat(provider.getScopes(), IsArrayContaining.hasItemInArray(scope2));
assertThat(provider.getScopes(), IsArrayContaining.hasItemInArray(scope3));
}
示例4: getClient
private GoogleApiClient getClient(SuccessCallback<GoogleApiClient> onConnected) {
if (mGoogleApiClient == null) {
Context ctx = AndroidNativeUtil.getContext();
if (mGoogleApiClient == null) {
GoogleSignInOptions gso;
if (clientId != null && clientSecret != null) {
System.out.println("Generating GoogleSignIn for clientID="+clientId);
List<Scope> includeScopes = new ArrayList<Scope>();
Scope firstScope = new Scope(Scopes.PROFILE);
if (scope != null) {
for (String str : Util.split(scope, " ")) {
if ("profile".equals(str)) {
//str = Scopes.PROFILE;
continue;
} else if ("email".equals(str)) {
str = Scopes.EMAIL;
} else if (Scopes.PROFILE.equals(str)) {
continue;
}
if (str.trim().isEmpty()) {
continue;
}
includeScopes.add(new Scope(str.trim()));
}
}
gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
//.requestIdToken("555462747934-iujpd5saj4pjpibo7c6r9tbjfef22rh1.apps.googleusercontent.com")
.requestIdToken(clientId)
.requestScopes(firstScope, includeScopes.toArray(new Scope[includeScopes.size()]))
//.requestScopes(Plus.SCOPE_PLUS_PROFILE)
//.requestServerAuthCode("555462747934-iujpd5saj4pjpibo7c6r9tbjfef22rh1.apps.googleusercontent.com")
.requestServerAuthCode(clientId)
.build();
} else {
System.out.println("Generating GoogleSignIn without ID token");
gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN).build();
}
mGoogleApiClient = new GoogleApiClient.Builder(ctx)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
}
}
if (mGoogleApiClient.isConnected()) {
if (onConnected != null) {
onConnected.onSucess(mGoogleApiClient);
}
} else {
synchronized(onConnectedCallbacks) {
if (onConnected != null) {
onConnectedCallbacks.add(onConnected);
}
if (!mGoogleApiClient.isConnecting()) {
mGoogleApiClient.connect(GoogleApiClient.SIGN_IN_MODE_OPTIONAL);
}
}
}
return mGoogleApiClient;
}