本文整理汇总了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;
}