开始使用java中的Android应用程序,并且不知道如何正确迭代。
我有Google登录对象:
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestServerAuthCode(this.getString(R.string.auth_client_id))
.requestScopes(scopes)
.requestEmail()
.requestProfile()
.build();
范围数组:
// split scope params
String[] scopes = scope.split("\\+|_|__");
List<String> list = new ArrayList<>();
for (int i = 0; i < scopes.length; i++) {
list.add(new Scope(scopes[i]));
}
要在Google登录选项对象中迭代“.requestScopes(范围)”,因为.requestScopes()不允许我输入数组值,只允许使用字符串。
你的帮助可能会帮助我节省额外一半的时间。
答案 0 :(得分:1)
// split scope params
String[] scopeStrings = scope.split("\\+|_|__");
Scope firstScope = new Scope(scopeStrings[0]);
Scope[] scopes = new Scope[scopeStrings.length - 1];
for (int i = 1; i < scopeStrings.length; i++) {
scopes[i - 1] = new Scope(scopeStrings[i]);
}
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestServerAuthCode(this.getString(R.string.auth_client_id))
.requestScopes(firstScope, scopes)
.requestEmail()
.requestProfile()
.build();